Hi guys,
Wondering if someone can tell me if this is by any chance possible in C++.
Say I have a base class which has static members, and is never instantiated:
class X
{
...
};
Then I have 2 classes which inherit it and add more static stuff:
class Y : public X
{
...
};
and
class Z : public X
{
...
};
Is it possible to have a 'generic class pointer' to X,Y and Z which can be defined at runtime? Basically my program has three modes of operation provided as arguments, and each mode uses common functionality in X and adds more custom stuff. The problem is loads of other code in my program uses X for functionality and doesn't know about Y or Z because it doesn't need their functionality and because Y and Z where not envisioned during their design.
X has static functions in so it never has an instance created, so various places for example call X::doSomething();
What I want is to replace X::doSomething with genericPointerToStaticClass::doSomething, and that may invoke class X, Y or Z as defined at runtime.
Can that be done or am I dreaming, I think it might relate to polymorphism but its been a while since I looked at that. Hope I explained it ok.
And i suppose when i say pointer, thats not really what i mean because the classes never have an instance :S
Thanks,
Jack
Wondering if someone can tell me if this is by any chance possible in C++.
Say I have a base class which has static members, and is never instantiated:
class X
{
...
};
Then I have 2 classes which inherit it and add more static stuff:
class Y : public X
{
...
};
and
class Z : public X
{
...
};
Is it possible to have a 'generic class pointer' to X,Y and Z which can be defined at runtime? Basically my program has three modes of operation provided as arguments, and each mode uses common functionality in X and adds more custom stuff. The problem is loads of other code in my program uses X for functionality and doesn't know about Y or Z because it doesn't need their functionality and because Y and Z where not envisioned during their design.
X has static functions in so it never has an instance created, so various places for example call X::doSomething();
What I want is to replace X::doSomething with genericPointerToStaticClass::doSomething, and that may invoke class X, Y or Z as defined at runtime.
Can that be done or am I dreaming, I think it might relate to polymorphism but its been a while since I looked at that. Hope I explained it ok.
And i suppose when i say pointer, thats not really what i mean because the classes never have an instance :S
Thanks,
Jack