【C++编程】调用基类的虚函数

调用基类的虚函数

代码实现:

#include <iostream>

class Base {
public:
    virtual void f() { std::cout << "Base::base()" << std::endl; }
};

class Test : public Base {
public:
    void f() { std::cout << "Test::test()" << std::endl; }
};

int main()
{
    Base *b = new Test();
    b->Base::f();
    b->f();
}

 

posted @ 2022-04-14 11:00  苏格拉底的落泪  阅读(111)  评论(0编辑  收藏  举报