Inheritance and method overloading

后端 未结 1 520
清歌不尽
清歌不尽 2020-11-28 11:53

Why C++ compiler gives this error? Why i can access lol() from B, but can not access rofl() [without parameters]. Where is the catch?

class A
{
public:
   vo         


        
相关标签:
1条回答
  • 2020-11-28 12:50

    The B::rofl(int) 'hides' the A::rofl(). In order to have A's rofl overloads, you should declare B to be using A::rofl;.

    class B : public A {
    public: 
        using A::rofl;
        ...
    };
    

    This is a wise move of C++: it warns you that you probably also need to override the A::rofl() method in B. Either you do that, or you explicitly declare that you use A's other overloads.

    0 讨论(0)
提交回复
热议问题