title: Operators overloading (+=,=) for own strings
body: <p>I'm trying to create my own class string.
  I've got some issues with operator overloading.</p>
  
  <p><strong>My_string.h</strong></p>
  
  <pre><code>  #include &lt;cstring&gt;
    #include &lt;iostream&gt;
      class My_string
      {
      private:
          char *value;
      public:
          My_string();
          My_string(char *);
          ~My_string();
          My_string operator +=(const My_string&amp;);
          My_string operator =(const My_string&amp;);
          void show()const;
      };
  </code></pre>
  
  <p><strong>My_string.cpp</strong></p>
  
  <pre><code>#include "stdafx.h"
  #include "My_string.h"
  
  
  My_string::My_string()
  {
      value = new char[1];
      strcpy(value, "");
  }
  
  My_string::My_string(char * r_argument)
  {
  
      value = new char[strlen(r_argument) + 1];
      strcpy(value, r_argument);
  }
  
  My_string::~My_string()
  {
      delete[]value;
  }
  
  My_string My_string::operator+=(const My_string &amp;r_argument)
  {
      char * temp_value = new char[strlen(value) + strlen(r_argument.value) + 1];
      strcpy(temp_value, value);
      strcat(temp_value,r_argument.value);
      delete[]value;
      value = new char[strlen(value) + strlen(r_argument.value) + 1];
      strcpy(value, temp_value);
      delete[]temp_value;
      return *this;
  }
  
  void My_string::show() const
  {
      std::cout &lt;&lt; value &lt;&lt; std::endl;
  }
  
  My_string My_string::operator =(const My_string &amp; r_argument)
  {
      delete[] value;
      value = new char[strlen(r_argument.value)+1];
      strcpy(value, r_argument.value);
      return *this;
  }
  </code></pre>
  
  <p>How to overload +=  and = operators ?They both causes runtime errors. I need all to be in dynamically allocated memory.</p>
  
  <p>Debug Assertion Failed! 
  ...
  Expression: _CrtisValidHeapPointer(block).</p>