I am making for fun a String class and I want to be able to do something like :
myString a,b,c;
a = "a";
b = "b";
c = a + b;
But I cannot find how to use the + without changing the value of a.
Anyone?
Printable View
I am making for fun a String class and I want to be able to do something like :
myString a,b,c;
a = "a";
b = "b";
c = a + b;
But I cannot find how to use the + without changing the value of a.
Anyone?
That should get you started =).Code:myString operator + (const myString& lhs, const myString& rhs)
{
myString ret;
// do your stuff here...
return ret;
}
Z.
I do not need to return *this to be able to have multiple +?
Example a = b + c + d + e;
Take a look at my code.
What happens is enssentially this:
You will only return a *this when using an <operator>= type operator, which is where you would apply the changes to the object, and return *this as a reference return value.Code:in operator +:
ret = lhs + rhs;
return ret;
ret = b + c;
ret = ret + d;
ret = ret + e;
a = ret;
Z.
Interesting :)
Thx you Mister Z.