Share via


hash_map::const_reference

[!NOTA]

Esta API está obsoleta.La alternativa es unordered_map Class.

Un tipo que proporciona una referencia a un elemento const almacenados en un hash_map para leer y realizar operaciones const .

typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::const_reference const_reference;

Comentarios

En Visual C++ .NET 2003, los miembros de los archivos de encabezado <hash_map> y <hash_set> ya no están en el espacio de nombres std, pero se han movido bastante al espacio de nombres stdext.Vea El espacio de nombres stdext para obtener más información.

Ejemplo

// hash_map_const_ref.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_map<int, int> hm1;
   typedef pair <int, int> Int_Pair;

   hm1.insert ( Int_Pair ( 1, 10 ) );
   hm1.insert ( Int_Pair ( 2, 20 ) );

   // Declare and initialize a const_reference &Ref1 
   // to the key of the first element
   const int &Ref1 = ( hm1.begin( ) -> first );

   // The following line would cause an error because the 
   // non-const_reference cannot be used to access the key
   // int &Ref1 = ( hm1.begin( ) -> first );

   cout << "The key of the first element in the hash_map is "
        << Ref1 << "." << endl;

   // Declare and initialize a reference &Ref2 
   // to the data value of the first element
   int &Ref2 = ( hm1.begin( ) -> second );

   cout << "The data value of the first element in the hash_map is "
        << Ref2 << "." << endl;
}
  
  

Requisitos

Encabezado: <hash_map>

Stdext deEspacio de nombres:

Vea también

Referencia

hash_map Class

Biblioteca de plantillas estándar