I've been reading the Enginuity articles (amazing btw :D) and I have a quick, really dumb question. I've never dealt with static variables in a class before, so if you have a class like thus:
class IMMObject
{
private:
static std::list<IMMObject *> liveObjects;
statid std::list<IMMObject *> deadObjects;
long refCount;
protected:
IMMObject();
~IMMObject();
public:
void AddRef();
void Release();
static void CollectGarbage();
};
std::list<IMMObject *> IMMObject::deadObjects;
void IMMObject::Release()
{
--refCount;
if(refCount<=0)
{
liveObjects.remove(this);
deadObjects.push_back(this);
}
}
void IMMObject::CollectGarbage()
{
for(std::list<IMMObject *>::iterator it=deadObjects.begin();
it!=deadObjects.end(); it++)
{
delete (*it);
}
deadObjects.clear();
}
IMMObject::IMMObject()
{
liveObjects.push_back(this);
//update the constructor to initialise refCount to zero
refCount=0;
}
Any class that inherites or uses IMMObject will get the same copy of liveObjects and deadObjects right?
So:
IMMObject obj1;
liveObjects will contain obj1.
now lets say I go:
IMMObject obj2;
then liveObjects will contain obj1 and obj2, right?
Also, why is a method static? whats the point in this?
Cheers