1 #include <iostream>
2 #include <memory>
3 #include <allocators>
4 #include <cstdlib>
5 using namespace std;
6
7 class myclass
8 {
9 public:
10 myclass()
11 {
12 cout << "构造" << endl;
13 }
14 ~myclass()
15 {
16 cout << "析构" << endl;
17 }
18 //拷贝构造
19 myclass(const myclass &my)
20 {
21 cout << "拷贝构造" << endl;
22 }
23 };
24
25 void main()
26 {
27 allocator<myclass> my;//分配器
28 myclass *p = my.allocate(1);//分配
29 //my.construct(p);//手动调用自己的构造函数
30 my.construct(p, myclass());//手动调用拷贝构造函数
31 my.destroy(p);//手动调用析构
32 my.deallocate(p, 1);//释放内存
33
34 cin.get();
35 }