Problem with static attribute
Posted on 2000-04-14
I'm developing a MDI application. Consider the following class:
class CMyClass:public CObject
static UINT m_numberOfObjects;
m_number =++m_numberOfObjects ;
Every document opened handles a list of these objects.
As you may note ,m_numberOfObjects stores the amount of objects
of the same class .Its value should be increased whenever a new
object is created.Similarly m_number stores the number of the
object recently created.
This approach is Ok if there is only one one document opened .My
headache begins when I open another document :I want the variable to be
initialized to "0" because I'm working with another document and therefore
with another ,initially empty list , .The problem is
that it does not occur :since MyClass.h file is shared by all the documents
it doesn't store the number of the last object in the current document but
the number of the last object in all the docs.
Any idea to solve this problem ? (I hope you know what I mean)