我正在尝试使用以下函数为字符串和双精度定义运算符 +
string operator + (const double& b,const string a){
return to_string(b)+a;
}
当我进行以下操作时,它运行良好
double c = 100.256;
string d = "if only";
cout<<c+d<<"\n";
但是当我传递 const char 而不是 string 时,它会引发编译错误('double' 和 'const char [4]' 类型的无效操作数到二进制 'operator+')
double c = 100.256;
string test = c+"sff";
为什么 const char[] "sff" 到字符串的隐式转换没有发生?