Can someone explain me why I can't define something like that:
Class A {
A a;
//...
};
But I can define something like that:
Class A {
std::vector<A> vec;
//...
};
What is the difference that allow the second?
Can someone explain me why I can't define something like that:
Class A {
A a;
//...
};
But I can define something like that:
Class A {
std::vector<A> vec;
//...
};
What is the difference that allow the second?
You can't use the first because it is recursive, that is object A contains object A, and the second one you can use because vector doesn't contain object A but a pointer to object A.