In the following sample code, C++ allows container of self class. But if a single object is created it's not allowed. I understand that class can have pointer to self type or static member object.
But how is container of self (not self pointer) is allowed? How is compiler able to get 'complete definition' for vector members?
#include <iostream>
#include <vector>
class Test {
std::vector<Test> list; //but this works
static Test t3; // this is allowed too
// Test t2; // definition of 'class Test' is not complete
public:
Test() {
std::cout << "Test()" << std::endl;
std::cout << list.size() << std::endl;
}
};
int main() {
Test t;
return 0;
}