C++多态实现

#include <iostream>
using namespace std;

class A
{
public:
    void f()
    {
        cout << "AAAAAAAAAA" << endl;
    }
};
class B :public A
{
public:
    virtual void f()
    {
        cout << "BBBBBBBBBBB" << endl;
    }
};

int main()
{
    A *a = new B();
    a->f();
    return 0;
}

 

posted @ 2017-03-14 11:48  smile带着你  阅读(100)  评论(0编辑  收藏  举报