我对这种情况感到困惑,谷歌搜索没有给我答案.基本上我有以下不编译的简单代码:
#include <iostream>
class A
{
public:
int a(int c = 0) { return 1; }
static int a() { return 2; }
};
int main()
{
std::cout << A::a() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在编制本,GCC 4.2表示调用A::a()的main()是与暧昧的两个版本a()有效候选人.Apple的LLVM编译器3.0编译时没有错误.
为什么gcc对我要调用哪个函数感到困惑?我认为这是明显的,通过资格a()与A::我要求的static功能的版本.当然,如果我删除该static函数a(),这段代码仍然无法编译,因为A::a()它不是用于调用non的有效语法static a().
谢谢你的评论!
c++ ×1