|
-
Sep 21st, 2002, 03:56 PM
#1
Thread Starter
Ya ya Baby!!!Me is Back
operator+
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?
-
Sep 21st, 2002, 05:18 PM
#2
Frenzied Member
Code:
myString operator + (const myString& lhs, const myString& rhs)
{
myString ret;
// do your stuff here...
return ret;
}
That should get you started =).
Z.
-
Sep 22nd, 2002, 09:37 AM
#3
Thread Starter
Ya ya Baby!!!Me is Back
I do not need to return *this to be able to have multiple +?
Example a = b + c + d + e;
-
Sep 22nd, 2002, 10:06 AM
#4
Frenzied Member
Take a look at my code.
What happens is enssentially this:
Code:
in operator +:
ret = lhs + rhs;
return ret;
ret = b + c;
ret = ret + d;
ret = ret + e;
a = ret;
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.
Z.
-
Sep 22nd, 2002, 11:41 AM
#5
Thread Starter
Ya ya Baby!!!Me is Back
Interesting 
Thx you Mister Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|