为什么c ++编译器不会抱怨以下代码?
#include<iostream>
int main()
{
const char* p ="Hello";
std::string q = p + 'H';
std::cout << q << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
它正确地抛出了以下代码的错误
#include<iostream>
int main()
{
const char* p ="Hello";
std::string q = p + "World";
std::cout << q << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
编译器抛出的错误语句
test.cxx: In function 'int main()':
test.cxx:5: error: invalid operands of types 'const char*' and 'const char [6]' to binary 'operator+'
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我理解,为什么第一个代码没有抛出任何错误声明?