12
比方說,我有以下類別:從調用基類的重載方法
class A {
public:
virtual void foo() {
bar();
}
protected:
virtual void bar() {
// Do stuff
}
}
class B : public A {
protected:
virtual void bar() {
// Do other stuff
}
}
如果我有B的實例,並調用foo的方法,這條方法將被調用?這個編譯器是特定的嗎?
感謝
請注意,在基礎構造函數和析構函數中不是這種情況。在那裏它會調用基礎實現。討論:http://www.cplusplus.com/forum/general/109477/ –