Original Post
Got a little problem. I''m creating a String class, and I''m getting a weird compiler error. Here''s what I have so far.
The problem is with overloading the ''+'' operator. I want to be able to do something like this:
string3 = string1 + string2;And I figured that the best way to do it would be to create a temporary string object, set that object to the union of string1 and string2, and then return that temporary object. It would look like this. I wont put the whole code here, but rather just the general logic of it so you get the gist:
string operator + (string &string2)
{
string temp;
// Set temp.length equal to the added lengths of both strings involved.
// Use strcopy''s to copy data from both strings into temp''s buffer.
return temp;
}
So, the above expression would essentialy end up like this:
string3 = temp;And then I''ve overloaded the ''='' operator to do what''s expected. The problem is that I am getting this error that says "cannot return temporary" from the Bloodshed''s IDE (I forget which compiler it uses -- starts with M). Why the hell can''t I? This seems like the simplest, most logical thing to do. I''ve persued other methods, such as using a global temporary string object, as well as altering the calling object (in this case string1) so that it equals the result of string1 + string2. Nothing works. I even tried having the overloaded ''+'' function return a char*, and I overloaded ''='' to accept a char*, and I got the same dang message. Anyone know what I''m doing wrong? ---signature--- People get ready. I''m ready to play.