I would like to rewrite this for loop (which works)
for (vector<shared_ptr<Node<int>>>::iterator it = n.root.children.begin();
it != n.root.children.end();
++it)
{cout << (*it)->value<<flush;}
into a range-based for loop. What I tried is
for (shared_ptr<Node<int>> child:(n.root).children){
cout<<(child->value)<<" "<<flush;
}
but it gives me a core dump. The root is of type Node
template <typename T>
class Node{
public:
T value;
vector<shared_ptr<Node>> children;
};
These lines in main.cpp work fine.
cout<<(n.root).value<<flush;
cout<<n.root.children.front()->value<<flush;
I use g++ 4.7.2.
Here ya go. Try this.