Creating a tree using std :: array

The code below generates the following compile-time error. Errors disappear if I use std::vector<Node>or std::array<unique_ptr<Node>, 3>. Can someone explain what this means?

In the file included in main.cpp: 1: 0: / usr / include / c ++ / 4.9 / array: In an instance of 'struct std :: array: main.cpp: 9: 23:
requires / usr / include / c + from here + / 4.9 / array: 97: 56: error: 'Std :: array <_Tp, _Nm> :: _ M_elems has an incomplete type typename _AT_Type :: _ Type _M_elems; ^ main.cpp: 3: 7: error: forward Declaring a 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
};
+4
source share
3

, , .

, , , , , . Node, , Node.

, , , , , , .

, std::array<Node, 3> Node , std::array , ​​( , , , ). , , Node, .

std::unique_ptr<Node> , : .

a std::vector<Node> ( , ) , , , : vector 2 , Node . . "" vector Node, , .

, : std::array<std::unique_ptr<Node>, 3>

- , , , .

, , - , pimpl.

+3

A Node, , Nodes.
, :

. .

+3

, Node , 3 . , .

std::vector <Node> , .

:: < :: unique_ptr <Node> , 3 > , Node, .

+1

Source: https://habr.com/ru/post/1569389/


All Articles