在类声明中重载的运算符:
class Asdf{
operator float() const;
Asdf operator+(const Asdf&) const;
Asdf operator+(float);
}
int main()
{
Asdf object1, object2, object3;
//Receiving error: "more than one operator '+' matches these operands"
object1= object2 + object3;
_getch();
return 0;
}
错误:
:error C2666: 'Asdf::operator +' : 3 个重载有类似的转换 : 可能是 'Asdf Asdf::operator +(float)' :'Asdf Asdf::operator +(const Asdf &) const'
当我删除与重载float
转换运算符一起使用的所有转换时,代码会正确编译。