次の方法で共有


allocator::construct

指定された値に初期化される指定したアドレスにあるオブジェクトの特定の型を構築します。

void construct( 
   pointer _Ptr,  
   const Type& _Val 
); 
void construct( 
   pointer _Ptr,  
   Type&& _Val 
); 
template<class _Other> 
    void construct( 
        pointer _Ptr,  
        _Other&&... _Val 
    );

パラメーター

  • _Ptr
    オブジェクトの作成場所へのポインター。

  • _Val
    構築されたオブジェクトが初期化される値。

解説

一つ目のメンバー関数は new (void (*) _Ptr) [種類] (_Val) と同等です。

使用例

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

using namespace std;

int main( ) 
{
   vector <int> v1;
   vector <int>::iterator v1Iter;
   vector <int>:: allocator_type v1Alloc;

   int i;
   for ( i = 1 ; i <= 7 ; i++ )
   {
      v1.push_back( 3 * i );
   }

   cout << "The original vector v1 is:\n ( " ;
   for ( v1Iter = v1.begin( ) ; v1Iter != v1.end( ) ; v1Iter++ )
      cout << *v1Iter << " ";
   cout << ")." << endl;

   allocator<int>::pointer v1PtrA;
   int kA = 6, kB = 7;
   v1PtrA = v1Alloc.address( *find( v1.begin( ), v1.end( ), kA ) );
   v1Alloc.destroy ( v1PtrA );
   v1Alloc.construct ( v1PtrA , kB );

   cout << "The modified vector v1 is:\n ( " ;
   for ( v1Iter = v1.begin( ) ; v1Iter != v1.end( ) ; v1Iter++ )
      cout << *v1Iter << " ";
   cout << ")." << endl;
}
  

必要条件

ヘッダー: <memory>

名前空間: std

参照

関連項目

allocator クラス

左辺値と右辺値

左辺値参照宣言子: &

右辺値参照宣言子: &&