Static vector declarations

Hello :)

I was wondering if you could help me. I am following a tutorial where
in a class a static vector of a pointer to that class is declared something like

Example.h
class Example{

static std::vector<Example*> ExampleList;

}

This doesn't work unless

static std::vector<Example*> Example::ExampleList;

is added to the Example.cpp file. Can anyone explain this to me please? I'm not even sure if its related to the static or the vector or the fact that its self-referential.

Thanks!
The line in the header file doesn't actually create the object, it just says that such a vector will be created. The line in the source file is the actual construction/creation of the vector.
Brilliant thankyou! So could I have equally well added this in the constructor? Or would that be bad programming practice?
No, it's static so only one exists for all the classes; you only want to create one ever. Creating it in the constructor wouldn't make sense as that would try to create a vector every time you made an object.
Ah yes of course! Thank you very much for all your help!
Topic archived. No new replies allowed.