Derived class that does not inherit an overloaded method from the base class

I would like the method in the base class to call a pure virtual method to be implemented in the derived class. However, the base class's unitless method does not appear to be inherited by the derived class. What am I doing wrong? The compiler is MSVC12.

error C2660: "Derived :: load": function does not take 0 arguments

Here's a complete example (which won't compile due to an error):

struct Base
{
    void load() { load(42); }; // Making this virtual doesn't matter.
    virtual void load(int i) = 0;
};

struct Derived : Base
{
    virtual void load(int i) {};
};

int main()
{
    Derived d;
    d.load(); // error C2660: 'Derived::load' : function does not take 0 arguments
}

      

+3


source to share


2 answers


Oh, the derived class does inheritance void load()

.

But you are declaring void load(int i)

in a derived class, which means it is shaded.



Add using Base::load;

to Derived

to add all non-overridden definitions load

from Base

to the overload set in Derived

.

Alternatively, call Base

-class-version explicitly using the scope-permission-operator d.Base::load();

.

+11


source


You must explicitly call Base

: d.Base::load();

. I have no idea why, but it works. I assume the override hides all overloads.



+2


source







All Articles