It has been a long time since I did any C++ programming, and I would highly appreciate it if anyone can guide me with creating a Node class that has one of its private variable a list (or vector) of objects of the Node class.
I am hoping to create a class structure as such:
class Node {
private:
string ID;
vector < Node > list;
public:
Node();
void some_Function();
};
Is this the right approach? Is it possible for a class to have one of its private members as a list of objects of the same class type?
No, you cannot.
When you define an object of type vector<T>, T must be a complete type, which it's not until the end of the class definition.
Some compilers will accept the code anyway (they'll accept a vector of some incomplete type), but it's not allowed by the C++ standard.
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