Originally Posted by
laserlight
Because member names in the derived class hide corresponding member names in the base class, so you should use a using declaration to bring back the member names from the base class as necessary.
Would this be the appropriate solution
Code:
#include <iostream>
class A {
public:
virtual int oper(int x, int y) {
return x + y;
}
virtual double oper(double x, double y) {
return x + y;
}
};
class B : public A {
public:
virtual double oper(double x, double y) {
return x * y;
}
};
int main(void) {
A x;
B y;
std::cout << x.oper(1,2) << std::endl; // 3
std::cout << x.oper(1.10,2.0) << std::endl; // 3.1
std::cout << y.oper(1,2) << std::endl; // 2, not 3 because oper has derived class's member has overriden base class's name
std::cout << dynamic_cast<A&>(y).oper(1,2) << std::endl; // 3, realizes to use base class's member function for ints
std::cout << y.oper(1.10,2.0) << std::endl; // 2.2
return 0;
}
I have never run into this before. Does it come up anywhere in typical development or in the standard libraries?