如果我有一个基类,只有虚拟方法和基类的 2 个派生类,并且实现了这些虚拟方法。
我如何:
// causes C2259
BaseClass* base = new BaseClass[2];
BaseClass[0] = new FirstDerivedClass;
BaseClass[1] = new SecondDerivedClass;
或者:
// causes "base is being used without being initialized"
BaseClass* base;
// causes CC59 again
BaseClass* base = new BaseClass;
base[0] = FirstDerivedClass();
base[1] = SecondDerivedClass();
(或类似的东西)
...这样我就可以通过 s 访问BaseClass
s 方法DerivedClass
,但是通过指针和指针是DerivedClass
s 的数组?