allocator::rebind

將一個型別的一個配置器配置另一種型別物件的儲存區的結構。

template<class _Other>
   struct rebind {
   typedef allocator<_Other> other;
   };

參數

  • 其他
    記憶體配置項目的型別。

備註

這個結構會提供配置的不同實作之容器中的項目型別的記憶體非常有用。

成員樣板類別定義其他型別。它的唯一用途是提供型別名稱 allocator< _其他>將型別名稱命名 allocator<型別>。

以配置器物件型別 Aal ,您可以配置型別 _Other 物件與運算式:

A::rebind<Other>::other(al).allocate(1, (Other *)0)

或者,您可以撰寫型別命名為的指標型別(Pointer Type):

A::rebind<Other>::other::pointer

範例

// allocator_rebind.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef vector<int>::allocator_type IntAlloc;
int main( ) 
{
   IntAlloc v1Iter;
   vector<int> v1;

   IntAlloc::rebind<char>::other::pointer pszC =
      IntAlloc::rebind<char>::other(v1.get_allocator()).allocate(1, (void *)0);

   int * pInt = v1Iter.allocate(10);
}

需求

標題: <memory>

命名空間: std

請參閱

參考

allocator Class