title: I don't know why it occurs heap corruption(about memory allocation problem)
body: <p>it's course's one of project and its goal is to make fully-worked MyString Class. Until made destructor method, it was worked well. but in main.cpp, when i tried to use these method i made, it occurs heap corruption. i thought the problem comes up from order of calling destructor but i couldn't figure out where it occurred.</p>
  
  <p>try to check allocated memory(reverse called order)
  processing without destructor method(it works)</p>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>    void main() {
          MyString a = MyString("HELLOMYNAMEIS");
          char ab[10] = "thisiskrw";
          MyString c = ab;
          a = a + c;
          cout &lt;&lt; a;
  }
  </code></pre>
  
  <p><strong>MyString.cpp</strong></p>
  
  <pre><code>MyString::~MyString() {
      delete[] str_;
  }
  
  MyString operator+(const MyString&amp; lhs, const MyString&amp; rhs) {
      MyString a(lhs);
      MyString b(rhs);
      a += b;
      cout &lt;&lt; a;
      return a;
  }
  
  MyString&amp; MyString::operator+=(const MyString&amp; str) {
      int i = 0;
      if (this-&gt;capacity() &lt; (this-&gt;length_ + str.length_)) {
          char* temp = new char[this-&gt;length_ + str.length_+1];
          memset(temp, '\0', this-&gt;length_+str.length_+1);
          strcpy(temp, this-&gt;str_);
          for (int i = 0; i &lt; str.length_; i++) {
              temp[(this-&gt;length_) + i] = str.str_[i];
          }
          temp[this-&gt;length_ + str.length_] = '\0';
          strcpy(this-&gt;str_,temp);
          this-&gt;length_ = this-&gt;length_ + str.length_;
          delete[] temp;
      }
      else {
          for (int i = 0; i &lt; str.length_; i++) {
              this-&gt;str_[(this-&gt;length_) + i] = str.str_[i];
          }
          this-&gt;length_ = this-&gt;length_ + str.length_;
      }
      return *this;
  }
  </code></pre>
  
  <p>it will print string inside MyString object.</p>