我很困惑,为什么我不能访问void func(int i)
,有人可以帮我吗? 当然,这只是一个演示,可以帮助您轻松理解我的问题。它的真实代码非常庞大,我希望Base和Child中的成员函数都可用。为什么不能在这种情况下访问基类的成员函数?
输出总是是 **
double
2
**
struct base
{
void func(int i)
{
cout << "int" << endl;
cout << i << endl;
}
};
struct child : base
{
void func(double d)
{
cout << "double" << endl;
cout << d << endl;
}
};
child c;
c.func((int)2);
他们收到不同的参数。它们应该像重载一样进行操作(int变量会转到base/double变量以进入子进程)。并不是说我相信经过一个常数会产生任何可靠的结果。 – ciphermagi
@ciphermagi名称隐藏背后有一个很好的理由 - [见这个答案](http://stackoverflow.com/questions/1628768/why-does-an-overridden-function-in-the-derived-class-hide-other -overloads的最)。 – jrok