G
Greg Buchholz
/*
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 A> struct Nest
{
A n_val;
Nest<pair<A,A> > *n_next;
};
template<class T>
std:stream& operator<<(std:stream& o, const std:air<T,T>& p)
{
o << "[" << p.first << "," << p.second << "]";
return o;
}
template<class T>
std:stream& operator<<(std:stream& 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<int> g;
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;
}
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 A> struct Nest
{
A n_val;
Nest<pair<A,A> > *n_next;
};
template<class T>
std:stream& operator<<(std:stream& o, const std:air<T,T>& p)
{
o << "[" << p.first << "," << p.second << "]";
return o;
}
template<class T>
std:stream& operator<<(std:stream& 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<int> g;
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;
}