vector::get_allocator

 

用于返回的对象分配程序的复制构造矢量。

语法

Allocator get_allocator( ) const;

返回值

矢量使用的分配器。

备注

矢量类的分配器指定类如何管理存储。  默认分配程序都附有 STL 容器类用于大多数编程的需要即可。  拥有分配编写和使用程序类是高级 C++ 主题。  

示例

// vector_get_allocator.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;
   // The following lines declare objects that use the default allocator.
   vector<int> v1;
   vector<int, allocator<int> > v2 = vector<int, allocator<int> >(allocator<int>( )) ;

   // v3 will use the same allocator class as v1
   vector <int> v3( v1.get_allocator( ) );

   vector<int>::allocator_type xvec = v3.get_allocator( );
   // You can now call functions on the allocator class used by vec
}

要求

标头: <vector>

命名空间: std

请参阅

vector 类
标准模板库