#include <iostream> using std::cout; class A{ public: virtual void f(){cout << "A f\n";} }; class B:public A{ public: void f(){cout << "B f\n";} }; void test(A*p) { (*p).f(); } int main() { B b; test(&b); return 0; }
输出: