dimanche 29 mars 2015

Why static variable needs to be explicitly defined?


In the class:



class foo
{
public:
static int bar; //declaration of static data member
};

int foo::bar = 0; //definition of data member


We have to explicitly define the static variable, otherwise it will result in a



undefined reference to `foo::bar'


My question is:


Why do we have to give an explicit definition of a static variable?


Please note that this is NOT a duplicate of previously asked undefined reference to static variable questions. This question intends to ask the reason behind explicit definition of a static variable.




Aucun commentaire:

Enregistrer un commentaire