Error initializing a vector with local objects
<p>I want to create a vector with diferent object of type A but ...</p>

<p>This code throws this exception:
     free(): invalid pointer: 0x0000000000401757 ***</p>

<pre><code>#include &lt;vector&gt;

class A
{
    char * elem;

public:
    A()
    {
        elem = new char[10];
    }
    void setA(char* name)
    {
        elem = name;
    }
    ~A()
    {
        delete[] elem;
    }

};

int main(int argc, char **argv)
{
    std::vector&lt;A&gt; v_a;
    for (int i = 0; i &lt; 10; ++i)
    {
        A m_a;
        m_a.setA("jaja");
        v_a.push_back(m_a);

    }
}
</code></pre>

<p>Why this is happening?? How can implement a correct solution?</p>