Overloading += as compared to +
<p>I need to overload operators + and += for MyString class.</p>

<p>MyString.h</p>

<pre><code>    class MyString
    {
        char* m_pStr;   
    };
</code></pre>

<p>Main</p>

<pre><code>    MyString s1("ABC"), s2("kkk");
    MyString s("S");//GMV
    s1 +=s;
    s2 = s+s1;
    stop
</code></pre>

<p>MyString.cpp</p>

<pre><code>MyString MyString:: operator + (const MyString &amp; rhs){
    char * tmp = create_tmp_string(this-&gt;m_pStr, rhs.m_pStr);
    return MyString(tmp);
};

MyString &amp; MyString:: operator += (const MyString &amp; rhs){
    char * tmp = create_tmp_string(this-&gt;m_pStr, rhs.m_pStr);
    return MyString(tmp);
};

char* MyString:: create_tmp_string(char * one, char * two){
    int total_length = strlen(one) + strlen(two);
    char * tmp = new char[total_length + 1];
    tmp[0] = '\0';
    strcat(tmp, one);
    strcat(tmp, two);   
    return tmp;
}
</code></pre>

<p>My problem is: </p>

<pre><code>s2 = s+s1; // Working
s1 +=s; // Not working.
</code></pre>

<p>Well, when I execute the code step by step:</p>

<pre><code>MyString &amp; MyString:: operator += (const MyString &amp; rhs){
    char * tmp = create_tmp_string(this-&gt;m_pStr, rhs.m_pStr);
    return MyString(tmp);
};
</code></pre>

<p>tmp turnes out to be SABC. But s1 will not contain SABC and remains holding ABC.</p>

<p>Could you help me?</p>
