title: pointer to a vector: getting segmentation fault
body: <p>I'm getting the segmentation fault in the following code. Could you please help me to figure it out? In the following code, it prints "ok here". Once it deallocates the memory, it shows the segmentation fault. But why ? any solution ?</p>
  
  <p>Any help on this will be appreciated.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class Cube
  {
  public:
      char *str;
  
      Cube(int len)
      {
          str = new char[len+1];
      }
      Cube(const Cube &amp;c)
      {
          str = new char[strlen(c.str) + 1];
          strcpy(str, c.str);
      }   
      ~Cube()
      {
          delete [] str;
      }
  };
  
  void foo(vector &lt;Cube&gt; *vec)
  {
      for (int i = 0; i &lt; 10; i++)
      {
          char in [] = "hello !!";
          Cube *c = new Cube(strlen(in)+1);
          strcpy(c-&gt;str, in);
          vec-&gt;push_back(*c);
          cout &lt;&lt; "ok here" &lt;&lt; endl;
          delete [] c;
      }
  }
  
  int main()
  {
      vector &lt;Cube&gt; vec;
  
      foo(&amp;vec);  
      return 0;    
  }
  </code></pre>