allocator::allocator

用來建立該物件之建構函式(Constructor)建立配置器物件。

allocator( ); 
allocator(
   const allocator<Type>& _Right
);
template<class Other>
   allocator(
      const allocator<Other>& _Right
   );

參數

  • _Right
    要複製的配置器物件。

備註

建構函式不會執行任何動作。不過,一般而言,從另一個配置器物件建構的配置器物件應該相等並允許混合物件配置和釋放在兩個配置器物件之間。

範例

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

using namespace std;

class Int {
public:
   Int( int i ) 
   {
      cout << "Constructing " << ( void* )this  << endl; 
      x = i;
      bIsConstructed = true;
   };
   ~Int( ) 
   {
      cout << "Destructing " << ( void* )this << endl; 
      bIsConstructed = false;
   };
   Int &operator++( ) 
   {
      x++;
      return *this;
   };
   int x;
private:
   bool bIsConstructed;
};

int main( ) 
{
   allocator<double> Alloc;
   vector <Int>:: allocator_type v1Alloc;

   allocator<double> cAlloc(Alloc); 
   allocator<Int> cv1Alloc(v1Alloc);

   if ( cv1Alloc == v1Alloc )
      cout << "The allocator objects cv1Alloc & v1Alloc are equal."
           << endl;
   else
      cout << "The allocator objects cv1Alloc & v1Alloc are not equal."
           << endl;

   if ( cAlloc == Alloc )
      cout << "The allocator objects cAlloc & Alloc are equal."
           << endl;
   else
      cout << "The allocator objects cAlloc & Alloc are not equal."
           << endl;
}
  
  

需求

標題: <memory>

命名空間: std

請參閱

參考

allocator Class