025 怎么又是Fun和Do

#include <iostream>
using namespace std;
class A {
private:
    int nVal;
public:
    void Fun()
    {
        cout << "A::Fun" << endl;
    };
    virtual void Do()
    {
        cout << "A::Do" << endl;
    }
};
class B :public A {
public:
    virtual void Do()
    {
        cout << "B::Do" << endl;
    }
};
class C :public B {
public:
    void Do()
    {
        cout << "C::Do" << endl;
    }
    void Fun()
    {
        cout << "C::Fun" << endl;
    }
};
void Call(

    // 在此处补充你的代码
    A * p
) {
    p->Fun(); p->Do();
}
int main() {
    Call(new A());
    Call(new C());
    return 0;
}

posted @ 2022-02-22 11:05  icefield817  阅读(52)  评论(0编辑  收藏  举报