In the book C++ Primer I came across the statement: "When we mix strings and string or character literals, at least one operand to each + operator must be a string type"
I noticed the following were not valid:
#include<string>
int main()
{
using std::string;
string welcome = "hello " + "world"; //example 1
string short_welcome = 'h' + 'w'; //example 2
return 0;
}
- Question 1: Why does example 1 generate an error, since both operands are string literals?
- Question 2: Why is it that at least one of the operands must be a string?
- Question 3: Why does example 2 also generate an error?
I just want to understand what's going on behind the scenes.