给出以下示例,为什么我必须明确使用语句b->A::DoSomething()
而不是仅仅是?C++过载分辨率
编译器的重载分辨率不应该找出我正在谈论的方法吗?
我使用微软VS 2005(注:使用虚拟在这种情况下,并不能帮助。)
class A
{
public:
int DoSomething() {return 0;};
};
class B : public A
{
public:
int DoSomething(int x) {return 1;};
};
int main()
{
B* b = new B();
b->A::DoSomething(); //Why this?
//b->DoSomething(); //Why not this? (Gives compiler error.)
delete b;
return 0;
}
我试图在类A中使用指向类B的指针调用DoSomething()。 – Abe 2008-09-16 13:22:25