Overloading a super class's function

淺唱寂寞╮ 提交于 2019-12-05 02:47:12

You need to use a using declaration inside the definition of class B:

class B : public A {
public:
    using A::foo;          // allow A::foo to be found
    void foo(int, int);
    // etc.
};

Without the using declaration, the compiler finds B::foo during name lookup and effectively does not search base classes for other entities with the same name, so A::foo is not found.

You're not overriding A::foo(int)'s implementation, instead you're aliasing A::foo and changing its signature to (int,int) instead of (int). As James McNellis mentioned the using A::foo; declaration makes the function from A available.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!