如果在派生类中定义了和基类同名的方法,那么基类中的方法就会被覆盖,在派生类中变得不可用,例如:
#include <string>
class homer
{
public:
//int doh(int) const {return 1;}
// char doh(char) const {return 'd';}
float doh(float) const {return 1.0;}
};
class bart : public homer
{
public:
class milhouse {};
void doh(std::string) const {}
};
int main()
{
const bart b;
b.doh(1); //error C2664: 'bart::doh' : cannot convert parameter 1 from 'int' to 'std::string'
b.doh('x'); //error C2664: 'bart::doh' : cannot convert parameter 1 from 'char' to 'std::string'
b.doh(1.0f); //error C2664: 'bart::doh' : cannot convert parameter 1 from 'float' to 'std::string'
return 1;
}