allocator::allocator
Konstruktory używane do tworzenia obiektów programu przydzielania.
allocator( );
allocator(
const allocator<Type>& _Right
);
template<class Other>
allocator(
const allocator<Other>& _Right
);
Parametry
- _Right
Program przydzielania obiekt do skopiowania.
Uwagi
Konstruktor nic nie robi.Ogólnie jednak obiekt alokatora zbudowane z innego obiektu programu przydzielania należy porównać go równa i umożliwić intermixing obiekt alokacji i zwalnianie między dwoma obiektami programu przydzielania.
Przykład
// 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;
}
Wymagania
Nagłówek: <memory>
Obszar nazw: std