Dynamically allocate array of std::string
<p>I want to dynamically allocate an array of <code>std::string</code>. There is a function to allocate. I can call the function as many number of times as I want through out the program. If the pointer to the array is already allocated, I want to release the memory first then allocated the new one.</p>

<p>Here is what I tried:</p>

<pre><code>std::string *names;
bool already_allocated = false;
void allocate( int n)
{
    if( already_allocated)
    {
        delete names;
    }
    names = new std::string[n];
    already_allocated = true;
}

int main()
{
    allocate(5);
    allocate(6);
    return 0;
}
</code></pre>

<p>But it is giving runtime error in the 2nd <code>allocate()</code> call for the line <code>delete names</code></p>

<p>Am I misunderstanding something?</p>
