class SuperBase
{
virtual void func() = 0;
};
template <typename Child>
class Base: public SuperBase
{
void func()
{
cout<< static_cast<Child*>(this)->m_i;
}
};
class Derived1: Base<Derived1>
{
static const int m_i;
}
const int Derived1:m_i = 1;
int main()
{
SuperBase *iob;
iob = new Derived1();
iob->func();
return 0;
}
Now if I want to intoduce more derived class like Derived 2, and I want to pass different value to Base like -
class Derived2: Base { //static const int m_i2; }
then I will not be able to do the same. Any design tweaks which can solve the problem ?
func
can calledderived_func
which would them deal with the variables, butderived_func
has to be the same name across all subclasses and has to be individually programmed (they can have a default in the base class)