allocator::allocator
用于的构造函数创建分配程序对象。
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;
}
要求
页眉: <内存>
命名空间: std