相关疑难解决方法(0)

如果我要覆盖它,我可以调用基类的虚函数吗?

假设我有课程FooBar设置如下:

class Foo
{
public:
    int x;

    virtual void printStuff()
    {
        std::cout << x << std::endl;
    }
};

class Bar : public Foo
{
public:
    int y;

    void printStuff()
    {
        // I would like to call Foo.printStuff() here...
        std::cout << y << std::endl;
    }
};
Run Code Online (Sandbox Code Playgroud)

正如在代码中注释的那样,我希望能够调用我所覆盖的基类函数.在Java中有super.funcname()语法.这在C++中是否可行?

c++ overriding virtual-functions

315
推荐指数
5
解决办法
22万
查看次数

标签 统计

c++ ×1

overriding ×1

virtual-functions ×1