L
lou zion
hello all,
i'm trying to wrap my head around this one, but something's missing. I'm
trying to create a class where all instances share a common variable that is
an instance of a different class. so, thought i'd use a static variable.
but, where can i initialize it?
myclass.h
-------------------
class MainClass()
{
declarations...
static OtherClass OC; // oc should be the same across all classes.
changes by one class instance change it in all instances
...
}
myclass.cpp
---------------------
#include myclass.h
//i want to initialize my static variable OC here so all classes can see it,
but how?
MainClass::MainClass(A1,A2,...): var1(A1), var2(A2)... // can't
initialize it here, cuz that's per instance, correct?
{
...
}
in a class module, when is code that is outside the class definition
executed? on the first instance? how and where can i initialize OC?
thanks!
lou
i'm trying to wrap my head around this one, but something's missing. I'm
trying to create a class where all instances share a common variable that is
an instance of a different class. so, thought i'd use a static variable.
but, where can i initialize it?
myclass.h
-------------------
class MainClass()
{
declarations...
static OtherClass OC; // oc should be the same across all classes.
changes by one class instance change it in all instances
...
}
myclass.cpp
---------------------
#include myclass.h
//i want to initialize my static variable OC here so all classes can see it,
but how?
MainClass::MainClass(A1,A2,...): var1(A1), var2(A2)... // can't
initialize it here, cuz that's per instance, correct?
{
...
}
in a class module, when is code that is outside the class definition
executed? on the first instance? how and where can i initialize OC?
thanks!
lou