O
Old Wolf
The following code causes a segfault for me, why?
#include <list>
template<typename T>
struct Tree
{
std::list< Tree<T> > child;
};
int main()
{
Tree<int> bar;
std::list< Tree<int> > foo;
foo.push_back(bar);
}
If I reverse the order of the 'foo' and 'bar' declarations then I instead
get a compiler error "Compiler could not generate default constructor
for class Tree<int>". The problem is the same with other types instead of
'int', but if I change list to vector or deque then there is no problem
at all.
#include <list>
template<typename T>
struct Tree
{
std::list< Tree<T> > child;
};
int main()
{
Tree<int> bar;
std::list< Tree<int> > foo;
foo.push_back(bar);
}
If I reverse the order of the 'foo' and 'bar' declarations then I instead
get a compiler error "Compiler could not generate default constructor
for class Tree<int>". The problem is the same with other types instead of
'int', but if I change list to vector or deque then there is no problem
at all.