G++ compiler cannot distinguish variable and function with the same name? [duplicate]

一曲冷凌霜 提交于 2019-12-06 07:10:54
struct Callable
{
    void operator()() const { }
};

struct Test
{
    void Call() { }
    Callable Call;
};

int main()
{
    Test x;
    x.Call(); // To which 'Call' does this refer?
}

Here's two reasons:

  • The variable might overload operator()
  • One might take the address of, or create references the function (using its name without associated function call ())

In the first case, what would variable() do? in the second, the compiler would have to determine the correct operation by the return type of an operation - which C++ does not allow for all sorts of reasons.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!