2

Please provide me with a specific answer why function overriding hides the functions that are overloaded in base class.

class Base{
public:
  fun(int,int);
  fun(B);
};
class Derived:public Base
{
public:
fun();
};

int main()
{
Derived d;
d.fun(1,2); // error
return 0;
}
ranganath111
  • 457
  • 2
  • 7
  • 17

1 Answers1

3

TTBOMK this doesn't have a real technical reason, it's just that Stroustrup, when creating the language, considered this to be the better default. (In this it's similar to the rule that rvalues do not implicitly bind to non-const references.)

You can easily work around it be explicitly bringing base class versions into the derived class' scope:

class Base {
public:
  void fun(int,int);
  void fun(Base);
};

class Derived : public Base {
public:
  using Base::fun;
  void fun();
};

Also refer WHY link as it tells why base overloaded method is hidden in derived class: WHY

Community
  • 1
  • 1
Abhineet
  • 6,459
  • 10
  • 35
  • 53