I have a static variable in my class , which I instantiate in the cpp file to value 1000.
class Container
{
private:
static long GLOBALID;
long MyID;
public:
Container();
long GetId();
};
The code for cpp file.
long Container::GLOBALID = 1000;
Container::Container()
{
MyID = GLOBALID++;
}
long Container::GetId()
{
return MyID;
}
When I print the ID value of container objects, they keep incrementing.
My question is that when I create a new object I instantiate the static varible to value 0f 1000 so why does it keep incrementing with each object created?
Aucun commentaire:
Enregistrer un commentaire