2

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?

Software_t
  • 576
  • 1
  • 4
  • 13

1 Answers1

1

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.