Won't this infinitely create new objects?

Because in every object there will be a vector of CEntity's created? Or will it not because it is static? And why do I need to type it again in the cpp file?

In the .h file.
1
2
3
4
5
6
7
class CEntity
{
public:
    static std::vector<CEntity*> EntityList;

...


In the .cpp file.
 
std::vector<CEntity*> CEntity::EntityList;
Last edited on
closed account (N36fSL3A)
No. Vectors don't allocate memory for objects unless you tell them too.

It doesn't know how many objects to create.
Last edited on
Ok, but when I want to use the vector do I just type CEntity::EntityList or does all the different objects I make of CEntity have a vector for themselfs?
That vector stores pointers, not CEntity objects. That alone prevents recursion.

It is static, so there is only one vector.

ODR -- One Definition Rule. The constructor of the static vector must be called exactly once within the binary. The line in .cpp generates that call to constructor.
Topic archived. No new replies allowed.