Code:
String& operator+(String &s1, const char *s2)
{
s1.b += s2;
return s1;
}
String& operator+(String &s1, String &s2)
{
s1.b += s2.b;
return s1;
}
operator + shall not modify its arguments.
I imagine you would it pretty strange if:
Code:
int x = 10;
int y = 5;
int z = x + y;
Results in x = 15, y = 5, z = 15.
But that's precisely what your code would do to a string object.
Furthermore, you must never return a reference to a temporay.
So the correct version would be:
Code:
String operator + (const String& s1, const char* s2)
{
String tmp(s1);
tmp.b += s2;
return s1;
}