title: Can't delete a heap instance of my custom class (C++)
body: <p>Here's what I've got:</p>
  
  <pre><code>class MyClass {
      int holder;
  public:
      MyClass() {
          holder = 5;
      }
  };
  </code></pre>
  
  <hr>
  
  <pre><code>template&lt;class T&gt;
  class First {
      std::vector&lt;T&gt; items;
  public:
      First() {
          T* tmp;
          for (int i = 0; i &lt; 20; i++) {
              tmp = new T();
              items.push_back(*tmp);
          }
      };
      ~First() {
          for (int i = 0; i &lt; 20; i++) {
              delete items.at(i);
          }
      };
  };
  </code></pre>
  
  <hr>
  
  <pre><code>class Second {
      std::vector&lt;std::deque&lt;First&lt;MyClass&gt;&gt;&gt; items;
  public:
      Second() {
          std::deque&lt;First&lt;MyClass&gt;&gt;* tmp;
          for (int i = 0; i &lt; 10; i++) {
              tmp = new std::deque&lt;First&lt;MyClass&gt;&gt;;
              items.push_back(*tmp);
          }   
      };
      ~Second() {
          for (int i = 0; i &lt; 10; i++) {
              for (int j = 0; j &lt; items.at(i).size(); j++) {
                  delete items.at(i).at(j); // this deletes the "First" instances
              }
              delete items.at(i); // this deletes the deque
          }
      };
  };
  </code></pre>
  
  <hr>
  
  <p>In my <code>main</code>, I'm create an instance of <code>Second</code> and adding <code>First</code> instances to it (through methods that aren't included). At the end of <code>main</code>, I delete the instance of <code>Second</code>, which should delete all the instances of <code>First</code> and the <code>deques</code>. However, I'm getting the following errors:</p>
  
  <pre><code>error: cannot delete expression of type 'value_type' (aka 'MyClass')
  error: cannot delete expression of type 'value_type' (aka 'First&lt;MyClass&gt;')
  error: cannot delete expression of type 'value_type' (aka 'std::deque&lt;First&lt;MyClass&gt;&gt;')
  </code></pre>
  
  <p>Essentially, all my <code>delete</code> commands are throwing errors. What am I missing here? I need to manually implement a destructor because I created a bunch of stuff on the heap - correct?</p>