title: How to properly deallocate memory?
body: <p>Classes:</p>
  
  <pre><code>class Menuitem
  {
  private:
      char* text;
  
      Menuitem();
      Menuitem(const char*);
      ~Menuitem();
      Menuitem(const Menuitem&amp; ) = delete;
      Menuitem&amp; operator=(const Menuitem&amp; ) = delete;
      friend class Menu;
  public:
  };
  
  class Menu
  {
  private:
      char* title;
      Menuitem* items;
      int identation = 0;
      int amount = 0;
  public:
      Menu();
      Menu(const char*, int = 0);
      ~Menu();
      bool isEmpty() const;
      int run() const;
      void add(const char*);
      void display() const;
      Menu&amp; operator=(const char* nTitle);
      operator int() const;
      Menu&amp; operator=(const Menu&amp; );
      operator bool() const;
      Menu&amp; operator&lt;&lt;(const char* );
  };
  </code></pre>
  
  <p>Functions:</p>
  
  <pre><code>Menu&amp; Menu::operator=(const char* nTitle)
  {
      if (nTitle[0] != '\0' &amp;&amp; title[0] != '\0')
      {
          delete[] title;
          title = new char[strlen(nTitle)+1];
          strcpy(title, nTitle);
      }
      else if (title[0] != '\0' &amp;&amp; nTitle == 0)
      {
          delete[] title;
          title = nullptr;
      }
      else
      {
          title = nullptr;
      }
      return *this;
  }
  
  Menu&amp; Menu::operator=(const Menu&amp; nMenu)
  {
      if (nMenu.title[0] != '\0' &amp;&amp; title[0] != '\0')
      {
          delete[] title;
          title = new char[strlen(nMenu.title)+1];
          strcpy(title, nMenu.title);
      }
      else if (nMenu.title[0] == '\0' &amp;&amp; title[0] != '\0')
      {
          delete[] title;
          title = nullptr;
      }
      else
      {
          title = nullptr;
      }
  
  
      if (!amount)
          for (int i = 0; i &lt; amount; i++)
          {
              if (items[i].text[0] != '\0')
              {
                  delete[] items[i].text;
                  items[i].text = nullptr;
              }
          }
      amount = 0;
  
      for (int i = 0; i &lt; nMenu.amount; i++)
      {
          if (nMenu.items[i].text != nullptr)
          {
              items[i].text = new char[strlen(nMenu.items[i].text)+1];
              strcpy(items[i].text, nMenu.items[i].text);
          }
          else
          {
              items[i].text = nullptr;
          }
      }
      amount = nMenu.amount;
      identation = nMenu.identation;
      return *this;
  }
  </code></pre>
  
  <p>My code has a lot of functions but I think that these (or maybe one of these) functions cause an error. The code displays what I need, but in the end when I clean the pointers from Menu using destructor </p>
  
  <blockquote>
    <p>Menu::~Menu(){delete[] title; delete[] items;}</p>
  </blockquote>
  
  <p>I receive these errors:</p>
  
  <blockquote>
    <p>malloc: Incorrect checksum for freed object 0x102832838: probably modified after being freed.</p>
  </blockquote>
  
  <p>Maybe I'm trying to double delete something, but I cant't find what and where</p>