map::const_reference
에 대 한 참조를 제공 하는 형식에 const 맵의 읽기 및 수행 하는 저장 된 요소의 const 작업.
typedef typename allocator_type::const_reference const_reference;
예제
// map_const_ref.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
map <int, int> m1;
typedef pair <int, int> Int_Pair;
m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
// Declare and initialize a const_reference &Ref1
// to the key of the first element
const int &Ref1 = ( m1.begin( ) -> first );
// The following line would cause an error as the
// non-const_reference cannot be used to access the key
// int &Ref1 = ( m1.begin( ) -> first );
cout << "The key of first element in the map is "
<< Ref1 << "." << endl;
// Declare and initialize a reference &Ref2
// to the data value of the first element
int &Ref2 = ( m1.begin( ) -> second );
cout << "The data value of first element in the map is "
<< Ref2 << "." << endl;
}
요구 사항
헤더: <map>
네임 스페이스: std