inhereted static member referencing
-
I have the following class:
class BaseClass { static char* wp; void Dynamic(char* s) { this->wp = s; } }
and a derivative:class Derived : public BaseClass { // static char* wp; // have been trying this, not sure if needed }
Basically, what I want to accomplish is this: I want to reference the static member wp of the derived class in the inhereted function and reference the BaseClass member in the Baseclass function so..BaseClass *bc = new BaseClass(); Derived *d = new Derived(); bc->Dynamic("something"); d->Dynamic("something else");
After this code, I want bc::wp != d::wp, but alas, bc::wp == d::wp == "something else". I would LIKE to have bc::wp == "something" and d::wp == "something else". Anybody have any clues as to how I might realise this? And yes I do realise I could make them non-static, but I am interested in a way of doing this... if at all possible. -
I have the following class:
class BaseClass { static char* wp; void Dynamic(char* s) { this->wp = s; } }
and a derivative:class Derived : public BaseClass { // static char* wp; // have been trying this, not sure if needed }
Basically, what I want to accomplish is this: I want to reference the static member wp of the derived class in the inhereted function and reference the BaseClass member in the Baseclass function so..BaseClass *bc = new BaseClass(); Derived *d = new Derived(); bc->Dynamic("something"); d->Dynamic("something else");
After this code, I want bc::wp != d::wp, but alas, bc::wp == d::wp == "something else". I would LIKE to have bc::wp == "something" and d::wp == "something else". Anybody have any clues as to how I might realise this? And yes I do realise I could make them non-static, but I am interested in a way of doing this... if at all possible.If you want the derived class to have its own, separate copy of the static member, you have to declare it in the derived class. Then, you also have to implement Dynamic() in the derived class so it refers to the derived class' static member and not the base class' static member.