【发布时间】:2017-04-14 12:32:50
【问题描述】:
std::string tmp;
tmp +=0;//compile error:ambiguous overload for 'operator+=' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'int')
tmp +=1;//ok
tmp += '\0';//ok...expected
tmp +=INT_MAX;//ok
tmp +=int(INT_MAX);//still ok...what?
第一个认为传递整数作为参数,对吗?为什么其他人通过编译?我在Visual C++和g++上测试过,我得到了与上面相同的结果。所以我相信我错过了标准定义的东西。这是什么?
【问题讨论】:
-
int将转换为char。但是对于0,很难说是NULL还是int 0