首页 > 代码库 > C++多态实现

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

 

C++多态实现