Why does an overridden function in the derived class hide other overloads of the base class?

后端 未结 4 2173
一整个雨季
一整个雨季 2020-11-21 05:07

Consider the code :

#include 

class Base {
public: 
    virtual void gogo(int a){
        printf(\" Base :: gogo (int) \\n\");
    };

    v         


        
4条回答
  •  故里飘歌
    2020-11-21 05:50

    This is "By Design". In C++ overload resolution for this type of method works like the following.

    • Starting at the type of the reference and then going to the base type, find the first type which has a method named "gogo"
    • Considering only methods named "gogo" on that type find a matching overload

    Since Derived does not have a matching function named "gogo", overload resolution fails.

提交回复
热议问题