Compartir a través de


allocator::allocator

Constructores utilizados para crear objetos de asignador.

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

Parámetros

  • _Right
    El objeto de asignador que se van a copiar.

Comentarios

El constructor no hace nada. Sin embargo, en general un objeto de asignador construido de otro objeto del asignador debe comparar el igual al y permitir la entremezcla de asignación de objetos y liberar entre los dos objetos de asignador.

Ejemplo

// 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;
}
  

Requisitos

Encabezado: <memory>

Espacio de nombres: std

Vea también

Referencia

allocator (Clase)