我有一個基類A和兩個類B,C派生自A.我們可以在類A中給出方法func的聲明。如何分別爲B和C定義方法func ?定義派生類中基類的未定義方法
class A {
public:
void func();
};
class B : public A {
//some members
};
class C : public A {
//some members
};
//define B's func here without changing the definition of the three classes
//define C's func here without changing the definition of the three classes
這是一個基本的_very_主題中C++和覆蓋在C++的書。我建議你拿起一本關於C++的好書(http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 –
不使用「虛擬」指令是不可能的。 A :: func()的地址必須被B :: func()或C :: func()覆蓋,並且只能在後期綁定時才能完成。 – Vink