📄 del_vector.cpp
字号:
#include <iostream>
#include <vector>
using namespace std;
int i=0,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;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -