Reputation: 13
Why in C++ it was done so that the compiler "forgets" about other methods with the same name but different parameters if you overrides one of such methods?
struct A {
void virtual f() {}
void virtual f(int) {}
void testA() {f(); f(1);} // OK
};
struct B : public A {
void f() override {}
void testB() {f(); f(1);} // Error
};
It seems that this is pointless behavior ... no?
Upvotes: 0
Views: 158
Reputation: 381
But you could add a using-statement to make all the A::f methods visible, something similar to this:
struct B : public A {
using A::f;
void f() override {}
void testB() {f(); f(1);} // No Error
};
Upvotes: 2
Reputation: 409216
When you override a member function in a child-class, you hide the name of the parent class, it's just how the language works. If you want to use a function from the parent class you have to be explicit, like e.g. A::f(1)
.
Upvotes: 1