473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Nested (non-regular) data types

/*
The program below causes my compiler to run out of memory.
I thought I'd run it past c.l.c++ to see if I made any obvious errors,
or, if this behavior was to be expected. I'm guessing the problem
comes from some sort of infinite recursion caused by the growing
type of the "Nest" data structure and the fact that a finite type
can't be statically resolved for second argument of "operator<<".
Thoughts?

Thanks,

Greg Buchholz

*/
#include<iostream>
#include<utility>

using namespace std;

template <class Astruct Nest
{
A n_val;
Nest<pair<A,A *n_next;
};

template<class T>
std::ostream& operator<<(std::ostream& o, const std::pair<T,T>& p)
{
o << "[" << p.first << "," << p.second << "]";
return o;
}

template<class T>
std::ostream& operator<<(std::ostream& o, const Nest<T>& p)
{
o << "{" << p.n_val ;

if(p.n_next) o << "," << *p.n_next;

return o << "}";
}

int main(int argc, char* argv[])
{
Nest<intg;
Nest<pair<int,int h;
Nest<pair<pair<int,int>,pair<int,int i;

g.n_val = 42; g.n_next = &h;
h.n_val = make_pair(43,44); h.n_next = &i;
i.n_val = make_pair(make_pair(45,46),make_pair(47,48)); i.n_next =
NULL;

cout << g << endl;

return 0;
}

Nov 2 '06 #1
1 1871
Greg Buchholz wrote:
/*
The program below causes my compiler to run out of memory.
Sure. Any attempt to instantiate 'Next<S>' also requires to
instantiate 'Nest<pair<S,S>>' which then requires to instantiate
'Nest<pair<pair<S,S>,pair<S,S>>>' and so on.
I thought I'd run it past c.l.c++ to see if I made any obvious errors,
or, if this behavior was to be expected.
Expected.
I'm guessing the problem
comes from some sort of infinite recursion caused by the growing
type of the "Nest" data structure and the fact that a finite type
can't be statically resolved for second argument of "operator<<".
I don't think that operator<< has anything to do with it.
Thoughts?
None, really. Don't do it.
>
Thanks,

Greg Buchholz

*/
#include<iostream>
#include<utility>

using namespace std;

template <class Astruct Nest
{
A n_val;
Nest<pair<A,A *n_next;
};

template<class T>
std::ostream& operator<<(std::ostream& o, const std::pair<T,T>& p)
{
o << "[" << p.first << "," << p.second << "]";
return o;
}

template<class T>
std::ostream& operator<<(std::ostream& o, const Nest<T>& p)
{
o << "{" << p.n_val ;

if(p.n_next) o << "," << *p.n_next;

return o << "}";
}

int main(int argc, char* argv[])
{
Nest<intg;
Nest<pair<int,int h;
Nest<pair<pair<int,int>,pair<int,int i;

g.n_val = 42; g.n_next = &h;
h.n_val = make_pair(43,44); h.n_next = &i;
i.n_val = make_pair(make_pair(45,46),make_pair(47,48)); i.n_next =
NULL;

cout << g << endl;

return 0;
}
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
13
by: Shailesh Humbad | last post by:
I wrote a short page as a quick reference to c++ integer data types. Any feedback welcome: http://www.somacon.com/blog/page11.php
3
by: lovecreatesbeauty | last post by:
Prof. Bjarne Stroustrup said "built-in data types have default constructor" at §10.4.2 in `TC++PL, special ed.'. He also said that "built-in data types are not classes" at §11.4 in `TC++PL,...
4
by: No One | last post by:
Here is my problem: I have a certain set of well-defined manipulations that I have to apply to different types of data. In all cases the manipulations are exactly the same, and are to be...
11
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to...
8
by: ramu | last post by:
Hi, I want to call a vc++ function from a c program on linux. So when I do this dosen't the VC++ datatypes differ with c datatypes. Because we don't have some vc++ data types in c. I have to...
11
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types when you create fields in a file. What is the...
3
by: Steve Teeples | last post by:
Can someone tell me how to access the "nested child" data of a specific parent from within a dataset? I read an XML file into a dataset with its schema and want to access the child nested data. ...
7
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced...
1
by: Krishna C | last post by:
what is the difference b/w VARRAY,RecordType,table type and nested tables data types?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.