我最近修复了一个错误。
在下面的代码中,重载函数之一是 const 而另一个不是。该问题将通过将两个函数设为 const 来解决。
我的问题是为什么编译器只在参数为 0 时才抱怨它。
#include <iostream>
#include <string>
class CppSyntaxA
{
public:
void f(int i = 0) const { i++; }
void f(const std::string&){}
};
int main()
{
CppSyntaxA a;
a.f(1); // OK
//a.f(0); //error C2666: 'CppSyntaxA::f': 2 overloads have similar conversions
return 0;
}