I'm new to C++. The book I read tells me that if the plus (+
) operator has been overloaded for some class object, say, the string
class, to make this problem more concrete.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s1("abc");
string s2("def");
string s3("def");
cout<<(s1+s2=s3)<<endl;
int x=1;
int y=2
int z=3;
cout<<(x+y=z)<<endl;
return 0;
}
As you may expect, the first cout
statement is correct while the second is wrong. The compiler complaints x+y
is not a modifiable lvalue. My question is why the +
operator returns a modifiable lvalue for string
objects but not for int
?