向量容器的问题
下面的程序我想输出a1的值该怎么写呢?#include<vector>
#include<iostream>
using namespace std;
int i=0;
int j=0;
class Cdemo
{
public:
Cdemo():str(NULL)
{
cout<<"constructor:"<<i++<<endl;
};
Cdemo(const Cdemo &cd)
{
cout<<"copy constructor:"<<i++<<endl;
this->str=new char[strlen(cd.str)+1];
strcpy(str,cd.str);
};
~Cdemo()
{
if(str)
{
cout<<"destructor:"<<j++<<endl;
delete [] str;
}
};
char *str;
};
int main()
{
Cdemo d1;
d1.str=new char[32];
strcpy(d1.str,"trend micro");
vector<Cdemo> *a1=new vector<Cdemo>();
a1->push_back(d1);
// delete a1; vector 对象指针能够自动析构
cout<<d1.str<<endl;
cout<<a1<<endl; //只输出a1的指针
return 0;
}