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;
}
现在,如果我想引入更多派生类,例如 Derived 2,并且我想将不同的值传递给 Base,例如 -
class Derived2: Base { //static const int m_i2; }
那么我将无法做到这一点。任何可以解决问题的设计调整?