Reputation: 586
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?
Upvotes: 2
Views: 89
Reputation: 73
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.
Upvotes: 1