Please note this is a question about template syntax only -- not general c++ object oriented, polymorphism design. This example is a fabrication for that purpose
Say I have a base class:
class A: public B
{
...
};
I use it...
A a;
a.DoSomething();
What If I wanted to do something like this, to be able have a compile-time derivation of A, not only from B but from other classes. So that I can use it like this:
A<B> a; // like class A : public B
a.doSomething();
A<C> ac; // like class A : public C
ac.DoSomething();
Can I do something like this?
template <typename BASECLASS>
class A : public BASECLASS
{
...
};
Let's assume my constructor had a parameter and I knew that whatever template I use for hte base class had the same signature. If so, this is the *.h file, what do you do with the *.cpp file? Is that legal for initializing the constructor?
A::A(int param) : BASECLASS(param)
{
}
Please note this is a question about template syntax only -- not general c++ object oriented, polymorphism design.