MyString mystring = "This" + "Not Working"; String Class Binary External Operator Overloading Problem
Posted on 2009-04-18
Regarding the classic C++ custom string class:
I am having a problem overloading the binary addition operator, so that I can add two literal strings to make a (for the sake of argument, what I am going to call...) MyString.
Take this example:
MyString mystring = "This" + "IsNotWorking";
I would expect the order of execution to be...
- mystring assigned value "This"
- mystring and "IsNotWorking" added together by overloaded class unary addition operator for adding a MyString object to a literal object.
I have both of these components working, I can assign from a literal, and I can add a MyString to a Literal.
The compiler is throwing "cannot add two pointers", which is fair comment, if the first thing the compiler does is the addition, and not the assignment. Is there a way around so that I can create an object from the overloaded addition of two constant literals?