del_vector.cpp
来自「01背包问题最简单实现」· C++ 代码 · 共 34 行
CPP
34 行
#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 + =
减小字号Ctrl + -
显示快捷键?