<1>若是父子類虛函數都有默認參數,這種狀況下根據指針類型來調用對應函數ide
<2>構造過程當中,虛表尚未創建,此時在構造或析構函數中調用虛函數爲靜態調用函數
<3>const類型函數和非const類型函數不構成覆蓋(多態)spa
<4>返回類型不一樣不構成覆蓋(多態),但能夠爲子類對象的指針或引用指針
經過虛表調用函數:對象
typedef void (*PFUNC)(void);it
typedef PFUNC* PVTAB;class
class A {引用
public:gc
virtual void foo (void) {im
cout << "A::foo() invoked" << endl;
}
virtual void bar (void) {
cout << "A::bar() invoked" << endl;
}
};
class B : public A {
public:
void foo (void) {
cout << "B::foo() invoked" << endl;
}
};
int main (int argc, char* argv[]) {
A a;
PVTAB pVtab = *(PVTAB*)&a;
cout << "A::VTAB[0] = " << (void*)pVtab[0] << endl;
(pVtab[0]) ();
cout << "A::VTAB[1] = " << (void*)pVtab[1] << endl;
(pVtab[1]) ();
B b;
pVtab = *(PVTAB*)&b;
cout << "B::VTAB[0] = " << (void*)pVtab[0] << endl;
(pVtab[0]) ();
cout << "B::VTAB[1] = " << (void*)pVtab[1] << endl;
(pVtab[1]) ();
return 0;
}
結果:
A::VTAB[0] = 00401087
A::foo() invoked
A::VTAB[1] = 00401267
A::bar() invoked
B::VTAB[0] = 00401082
B::foo() invoked
B::VTAB[1] = 00401267
A::bar() invoked