Udostępnij za pośrednictwem


vector::const_reference

Typ, który zawiera odniesienie do const przechowywane w wektorze do odczytu i wykonywania elementu const operacji.

typedef typename Allocator::const_reference const_reference;

Uwagi

Typ const_reference nie można zmodyfikować wartości elementu.

Przykład

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

int main( )
{
   using namespace std;
   vector <int> v1;
   
   v1.push_back( 10 );
   v1.push_back( 20 );

   const vector <int> v2 = v1;
   const int &i = v2.front( );
   const int &j = v2.back( );
   cout << "The first element is " << i << endl;
   cout << "The second element is " << j << endl;
   
   // The following line would cause an error as v2 is const
   // v2.push_back( 30 );
}
  

Wymagania

Nagłówek: <vector>

Obszar nazw: std

Zobacz też

Informacje

vector Class

Standardowa biblioteka szablonu