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; }
原文:http://www.cnblogs.com/kyxyes/p/3996201.html