So my sprout_node method is wrong.
I want to
a.) create a new (child) instance of a node
b.) have the current instance be its parent
c.) put the new child in the kids list
Really don't know how to do it in c++
Anyone have any ideas? thanks
//a.) create a new (child) instance of a node
node *n = new node;
//b.) have the current instance be its parent
n->parent = this;
//c.) put the new child in the kids list
this->kids.emplace_back(n);
note that I'm using dynamic allocation, that's because you've defined list<node *> kids;
¿do you have a good reason for that instead of list<node> kids;?
do you have a good reason for that instead of list<node> kids;
Containers of incomplete type invoke undefined behavior unless the standard specifies otherwise. (Until C++17, which defines the usual behavior for list, forward_list and vector of incomplete type.)
See http://en.cppreference.com/w/cpp/container/list#Template_parameters
hi ne555,
is there a reason why your 6th line has 'this' pointing at the list?
in my latest attempt I just stuck n in the kids list like it was a normal list ( not a list of pointers ). Will this work?