lundi 29 décembre 2014

Creating a tree using std::array

The code at the bottom generates the following compile-time error. The errors goes away if I use std::vector<Node> or std::array<unique_ptr<Node>, 3>. Can someone please explain what this is about?



In file included from main.cpp:1:0: /usr/include/c++/4.9/array: In instantiation of ‘struct std::array’: main.cpp:9:23:

required from here /usr/include/c++/4.9/array:97:56: error: ‘std::array<_Tp, _Nm>::_M_elems’ has incomplete type typename _AT_Type::_Type _M_elems; ^ main.cpp:3:7: error: forward declaration of ‘class Node’ class Node




#include <array>

class Node
{
public:
Node(Node* parent, int x) : parent_(parent), x_(x) {}
Node* parent_;
int x_;
std::array<Node, 3> children_; // ERROR
};

Aucun commentaire:

Enregistrer un commentaire