<分区>
在 C++ 中,我试图理解为什么在构造这样的字符串时不会出现错误:
const string hello = "Hello";
const string message = hello + ", world" + "!";
但是你会得到一个编译时错误:
const string exclam = "!";
const string msg = "Hello" + ", world" + exclam
编译时错误是:
main.cpp:10:33: error: invalid operands of types ‘const char [6]’ and
‘const char [8]’ to binary ‘operator+’
为什么第一次运行正常但第二次产生编译时错误?