#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;
}

 

输出:

 

posted on 2019-11-15 11:20  newbird2017  阅读(146)  评论(0编辑  收藏  举报