#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

class A
{
public:
    A(const char *str)
    {
        cptr = new char [strlen(str)];
        strcpy(cptr,str);
        cout<<"A(const char *str) called and cptr is "<<cptr<<endl;
    }
    A(const A &a)
    {
        cptr = new char [strlen(a.cptr)+1];
        strcpy(this->cptr,a.cptr);
        cout<<"A(const A &a) called and cptr is "<<cptr<<endl;
    }
    ~A()
    {
        cout<<"~A() called and cptr is "<<cptr<<endl;
        delete [] cptr;
    }

    char *cptr;
};

int main()
{
    A a1("1"),a2("2"),a3("3");
    vector<A> Avec;
    Avec.reserve(256);

    Avec.push_back(a1);
    Avec.push_back(a2);
    Avec.push_back(a3);

    vector<A>::iterator iter;
    for(iter = Avec.begin(); iter!=Avec.end(); )
    {
        if(strcmp((*iter).cptr,"1") == 0)
        {
            cout<<"before erase"<<endl;
            iter = Avec.erase(iter);
            cout<<"after erase"<<endl;
        }
        else
        {
            ++iter;
        }
    }
}