source from http://blog.csdn.net/steedhorse/article/details/333664
// Test.cpp #include <iostream> using namespace std; class Base { public: void f() { g(); } private: virtual void g() { cout << "Hi, MorningStar! I am g() of Base!." << endl; } }; class Derived : public Base { private: virtual void g() { cout << "Hi, MorningStar! I am g() of Derived." << endl; } }; int main() { Base *pB = new Derived(); pB->f(); delete pB; return 0; }
时间: 2024-11-29 00:25:05