Export (0) Print
Expand All

allocator::reference

A type that provides a reference to the type of object managed by the allocator.

typedef value_type& reference;

The reference type describes an object that can designate any object that an object of template class allocator can allocate.

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

using namespace std;

int main( ) 
{
   vector <double> v;
   vector <double> ::iterator vIter, vfIter;
   vector <double> :: allocator_type vAlloc;

   int j;
   for ( j = 1 ; j <= 7 ; j++ )
   {
      v.push_back( 100.0 * j );
   }

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

   vfIter = v.begin( );
   allocator<double>::reference vref =*vfIter;
   cout << "The value of the element referred to by vref is: "
        << vref << ",\n the first element in the vector." << endl;

   // nonconst references can have their elements modified
   vref = 150;
   cout << "The element referred to by vref after being modified is: "
        << vref << "." << endl;
}
The original vector v is:
 ( 100 200 300 400 500 600 700 ).
The value of the element referred to by vref is: 100,
 the first element in the vector.
The element referred to by vref after being modified is: 150.

Header: <memory>

Namespace: std

Show:
© 2014 Microsoft