容器配置器(allocator)(二)

来源:互联网 发布:电脑软件编程学校 编辑:程序博客网 时间:2024/06/05 07:21
#include <iostream>#include <list>namespace ClassFoo{void ListGetAllocatorExample1(){std::list<int> foo;int * p;// 用内存分配器分配包含5个元素的数组p = foo.get_allocator().allocate(5);// 为数组中的每个元素赋值for (int i = 0; i<5; ++i) p[i] = i;std::cout << "The allocated array contains:";for (int i = 0; i<5; ++i) std::cout << ' ' << p[i];std::cout << '\n';foo.get_allocator().deallocate(p, 5);}}int main(){ClassFoo::ListGetAllocatorExample1();return 0;}


本文原文:http://classfoo.com/ccby/article/pyO3ij

0 0
原创粉丝点击