Why will deleting 2D array in this way fail (C++)?
<p>In the following codes I try to build a 2D array with c++, but when I run this program it fails.  </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;

int obtain_options(  char ** optionLine)
{
   vector&lt; char*&gt; options;
   options.push_back("abc");
   options.push_back("def");


   std::copy(options.begin(), options.end(), const_cast&lt; char**&gt;(optionLine));

   return options.size();
}

int main(int ac, char* av[])
{
    char** optionLine;
    int len;
    optionLine = new char* [2];
    for (int i= 0; i&lt;2; i++)
    {
       optionLine[i] = new char [200];
    }
     obtain_options(optionLine);
    for (int i=0; i&lt;2; i++)
    {
        cout&lt;&lt;optionLine[i]&lt;&lt;endl;
     }

    for (int i=0; i&lt;2; i++)
        delete  [] (optionLine[i]);
    delete []optionLine;

   return 0;

} 
</code></pre>

<p>I understand there are some problems with allocating memory to optionLine in function obtain_options(), and if I change obtain_options() in this way, it will work:</p>

<pre><code>int obtain_options(  char ** optionLine)
{
    vector&lt; char*&gt; options;
    char *t1 = new char [100];
    t1[0] = 'a';
    t1[1] = 'b';
    t1[2] = 'c';
    t1[3] = '/0';
   options.push_back(t1);
    char *t2 = new char [100];
    t2[0] = 'd';
    t2[1] = 'e';
    t2[2] = 'f';
    t2[3] = '/0';
   options.push_back(t2);


   std::copy(options.begin(), options.end(), const_cast&lt; char**&gt;(optionLine));

   return options.size();
}
</code></pre>

<p>My question is if I do not change obtain_options(), how could I delete the 2D array optionLine in a proper way. </p>
