3

Consider the following code:

class Base
{
public:
    virtual void f1( int var, bool val ) {/*some implementation*/}
    virtual void f1( int var, int val )  {/*some implementation*/}
};

class Derived : public Base
{
public:
    void f1( int var, int val )  {/*new implementation*/}
};

if I create a new derived object:

Derived* newObj = new Derived();

and call f1:

newObj->f1(5, true);

why would it call Derived's f1, converting the bool to int? clearly the arguments don't match and there is a more suitable candidate at the base class (the base function that acceps int and bool). Why overriding an overloaded virtual function from the base hides its other implementations?

Яois
  • 3,718
  • 3
  • 25
  • 47
susdu
  • 812
  • 6
  • 20
  • 2
    Duplicate of http://stackoverflow.com/questions/1628768/why-does-an-overridden-function-in-the-derived-class-hide-other-overloads-of-the – Angelus Mortis Feb 29 '16 at 11:16

0 Answers0