相关疑难解决方法(0)

C++重载决议

鉴于以下示例,为什么我必须明确使用该语句b->A::DoSomething()而不仅仅是b->DoSomething()

编译器的重载决议不应该弄清楚我在谈论哪种方法?

我正在使用Microsoft 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;
}
Run Code Online (Sandbox Code Playgroud)

c++ overloading resolution function

36
推荐指数
4
解决办法
1万
查看次数

标签 统计

c++ ×1

function ×1

overloading ×1

resolution ×1