精華區beta EE_DSnP 關於我們 聯絡資訊
※ 引述《old000 (千)》之銘言: : 假設 class B 是繼承 class A : 那如果 A 裡面的 virtual function : 在 B 裡面沒有被implement : 這樣compile會過嗎? 像這樣... #include <iostream> using namespace std; class Base { public: virtual void f() { cout << "Base::f()" << endl; } void g() { cout << "Base::g()" << endl; } virtual void h() { cout << "Base::h()" << endl; } }; class Derived: public Base { public: void f() { cout << "Derived::f()" << endl; } void g() { cout << "Derived::g()" << endl; } }; int main() { Base *p = new Derived; p->f(); p->g(); p->h(); Base *q = new Base; q->f(); q->g(); q->h(); Derived *r = new Derived; r->f(); r->g(); r->h(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.131.138
old000:天啊 謝謝老師!<(_._)> 11/15 22:06