There are two problems.
First, you've overridden the copy constructor and the implicit conversion constructor from const char *, but not the assignment operator. On line 86 what you're actually doing is
|
s1 = overloadOprPlus("Hello ");
| |
The default assignment operator performs a bitwise copy of the members of overloadOprPlus, but overloadOprPlus has a non-trivial destructor. Once the temporary
overloadOprPlus("Hello ")
is destructed, s1 is left in an unrecoverable invalid state, becuase its pointer is left pointing to memory that has been deleted.
Second, your definition of the operator+() overload is nonsense. You implemented as if it was operator=().
The typical operator+() overload will follow these rules:
1. It will accept a const T & (where T is the same class).
2. It will return a T, which is constructed anew in the implementation.
3. It will be a const function (
this
will not be modified).
4. Its semantics should be analogous to addition for the given type (operators should not be repurposed willy-nilly without good reason).