#include <iostream>
#include <vector>
using namespace std;
class A
{
public:
A()
{
printf("A()\n");
}
~A()
{
printf("~A()\n");
}
A(const A& other)
{
printf("copy\n");
}
};
int main()
{
A *a = new A;
A *b = new A(*a);
A *c = new A(*b);
printf("------------------------\n");
vector<A*> vec;
vec.reserve(3);
vec.push_back(a);
vec.push_back(b);
vec.push_back(c);
for(auto it = vec.begin(); it != vec.end(); ++it)
{
delete *it;
}
return 0;
}
std::vector存放类的指针避免拷贝构造函数的调用
最新推荐文章于 2024-04-30 15:38:31 发布