allocator::address

尋找指定物件值的位址。

pointer address(
   reference _Val
   ) const;
const_pointer address(
   const_reference _Val
   ) const;

參數

  • _Val
    電子郵件地址搜尋物件的常數或 nonconst 值。

傳回值

物件的常數或 nonconst 指標找到,個別, const 或 nonconst 值。

備註

成員函式傳回 _Val電子郵件地址,以指標必須為配置的項目接受的格式。

範例

// allocator_address.cpp
// compile with: /EHsc
#include <memory>
#include <algorithm>
#include <iostream>
#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( 2 * i );
   }

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

   allocator<int>::const_pointer v1Ptr;
   const int k = 8;
   v1Ptr = v1Alloc.address( *find(v1.begin( ), v1.end( ), k) );
   // v1Ptr = v1Alloc.address( k );
   cout << "The integer addressed by v1Ptr has a value of: "
        << "*v1Ptr = " << *v1Ptr << "." << endl;
}
  
  

需求

標題: <memory>

命名空間: std

請參閱

參考

allocator Class