I am currently writing a custom string class that uses cstring to store the data. On top of that, I am writing operator overloads. Here is what I'm trying to perform:
I believe my assignment function is correct, but in my + operator function, I am trying to return a dead instance. I'm stuck and would GREATLY appreciate some help. Thanks.
If that new-expression throws an exception, your code will lose the user's data.
If you intend to implement operator +=:
1 2 3 4 5 6 7 8 9 10
T& operator+=(T const& other) {
// add other to *this
return *this;
}
// later (as a non-member)
T operator+ (T lhs, T const& other)
{ return lhs += other; }
// or as a member
T operator+ (T const& other)
{ T result = *this; return result += other; }