multimap::const_reference
Un tipo che fornisce un riferimento a un elemento const archiviare in un multimap per la lettura e l'esecuzione di operazioni const.
typedef typename allocator_type::const_reference const_reference;
Esempio
// multimap_const_ref.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
multimap <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 because the
// non-const_reference cannot be used to access the key
// int &Ref1 = ( m1.begin( ) -> first );
cout << "The key of the first element in the multimap 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 the first element in the multimap is "
<< Ref2 << "." << endl;
}
Requisiti
intestazione: <map>
Spazio dei nomi: deviazione standard