When you override, you override the name, not the specific overload. So it hides all overloads from the base class. To address, you can put using A::foo;
in your derived class to bring the overloads down into B
.
Why isn't a non overridden overloaded function being inherited when I override one of its other overloads? [duplicate]
-
16-07-2023 - |
Question
Say that six times fast... Why doesn't this compile in MSVC 2010?
class A {
public:
void foo(int a, int b) { };
void foo(int a) { };
};
class B: public A {
public:
void foo(int a, int b) { }; // <-- comment this out to compile
};
int main(int argc, char* argv[])
{
B b;
b.foo(1); // <-- doesn't compile... shouldn't B just inherit this overload?
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow