Yes, Joeman's suggestion does allow expressions such as: "hello" + str, but the definition of operator+ will expose char* to clients. I just don't like this idea. Basically my goal is that clients shouldn't see char*. I expect that you may pass char* to my original defintion of operator + and at the mean time char* will be IMPLICITLY converted to MyString. But obviously when a char* is on the left hand side of +, it failed to be converted to MyString. That is my question. How'd I make it possible. Thanks for your inputs.
Quote Originally Posted by laserlight View Post
Why not? It looks like you are giving operator+ the semantics of operator+=, which is a Bad Thing. Furthermore, your implementation of operator+ does unnecessary work: you should just create a buffer for the result, copy over what is necessary, then destroy a's contents and then make a's pointer point to the start of the new result buffer. (Of course, this would be after you have changed this to operator+=.)

EDIT:

Joeman's suggestion will allow expressions such as: "hello" + str. I do not see how that violates intuition. But what I had in mind was changing your current operator+ to take its first argument by const reference. This would also allow expressions such as "hello" + str, except that it will likely be less efficient than providing an overload of operator+ with a const char* first parameter.