class Node
{
string name;
Node previous;
};
Error: Node::previous uses "Node" which is being defined.
How can I get this to work in C++? It works in C#.
EDIT:
Why Node* previous
works?
Use pointers. Node* previous;
would solve the problem.
As you're doing it now, you actually try to make your class infinitely large.
Use a pointer or a reference.
For example:
Node* previous;
The only restriction is that a class cannot have an actual field of itself, likely for construction reason. Think about it, if every Box contains another Box inside it, how would you end up with a finite number of boxes?
If I'm not mistaken, C# only uses references for class types (as does Java), so you're using a reference there, just not seeing it.
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