これを for ループに書き直したいと思います (動作します)
for (vector<shared_ptr<Node<int>>>::iterator it = n.root.children.begin();
it != n.root.children.end();
++it)
{cout << (*it)->value<<flush;}
範囲ベースの for ループに変換します。私が試したのは
for (shared_ptr<Node<int>> child:(n.root).children){
cout<<(child->value)<<" "<<flush;
}
しかし、それは私にコアダンプを与えます。ルートは Node タイプです
template <typename T>
class Node{
public:
T value;
vector<shared_ptr<Node>> children;
};
main.cpp のこれらの行は正常に機能します。
cout<<(n.root).value<<flush;
cout<<n.root.children.front()->value<<flush;
g++ 4.7.2 を使用しています。