假设以下代码:
#include <iostream>
#include <string>
int func() { return 2; }
int main()
{
std::string str("str");
str = func();
std::cout << "Acquired value: '" << str << "'" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么行str = func();编译时没有出现类型不匹配的警告?
我正在使用编译器gcc v.4.7.1并设置-std = c ++ 11标志.
输出:
Acquired value: ''