比方說,我在C++的類層次結構:從一個類層次結構參數多態函數
class Base;
class Derived1 : public Base;
class Derived2 : public Base;
class ParamType;
class DerivedParamType1 : public ParamType;
class DerivedParamType2 : public ParamType;
而且我希望有一個多態函數,func(ParamType)
,在Base
定義採取DerivedParamType1
類型的參數爲Derived1
以及針對Derived2
的DerivedParamType2
類型的參數。
如果可能的話,如何在沒有指針的情況下完成這項工作?
我承認'指針'位有點麻煩。你期望多態只在使用指針時出現:/? – 2010-04-13 12:59:23
我的意思是我寧願傳遞給函數的參數最好是一個對象或引用而不是指針。 – myahya 2010-04-13 14:47:57