title: c++ correct use of delete after an assignment
body: <p>I'm a little bit confused on how to use correctly the delete keyword. Here is my scenario:</p>
  
  <pre><code>class Tuple {
  
  public:
  
      Tuple(int columns);
      ~Tuple();
  
      void set(int i, string d);
      string get(int i);
      int columnCount();
  
  private:
  
      string *data;
      int columns;
  
  };
  
  
  Tuple::Tuple(int columns) {
  
      this-&gt;columns = columns &gt; 0 ? columns : 0;
      if (this-&gt;columns  &gt; 0) {
          data = new string[this-&gt;columns];
      } else {
          data = 0;
      }
  
  }
  
  Tuple::~Tuple() {
      if (columns &gt; 0) {
          delete[] data; 
      }
  }
  
  void Tuple::set(int i, string d) {
  
      if (columns &gt; 0 &amp;&amp; i &gt; -1 &amp;&amp; i &lt; columns) {
          data[i] = d;
      }
  }
  
  class Table {
  
  public:
  
      Table(int columns);
      ~Table();
  
      void insertTuple(Tuple t);
      Tuple getTuple(int i);
  
      int columnCount();
      int rowCount();
  
  private:
  
      vector &lt;Tuple&gt; data;
      int columns;
      int rows;
  
  };
  </code></pre>
  
  <p>Now, when I call the following code I get a segfault:</p>
  
  <pre><code>        Tuple *outTuple;
          outTuple = new Tuple(cCount);
  
          for (int i=0; i&lt;cCount; i++) {
              tmpStr = string(reinterpret_cast&lt;const char*&gt;(sqlite3_column_text(statement, i)));
              outTuple-&gt;set(i, tmpStr);
          }
          (*outTable)-&gt;insertTuple(*outTuple);
  
          delete outTuple; //here I get segfault
  </code></pre>
  
  <p>What is wrong with my code? Is my code not well written? Can I improve it and avoid segfault?</p>