Attempting to create as simple parent/child node class but running into Incomplete Type Is Not Allowed error. Why?
class Node {
public:
Node ParentNode; //Error on this line
string NodeName;
Node(Node *node) : ParentNode(*node) {
}
};
You are trying:
Node ParentNode; //Error on this line
but Node is not a complete type at this point (you are in fact defining it at this point), a structure cannot contain an instance of itself, it can contain a pointer or reference to an instance of itself but not an actual instance. After all, if such recursive containment were allowed, where would it end?
The error hints at the fact that the definition of a class is incomplete while the class is being defined.
An object can't contain an instance of its own type – it would be infinitely large.
You want
Node* ParentNode;
and
Node(Node *node) : ParentNode(node)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With