hash_map::const_reference

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_map Class

提供對 const 項目之參考的型別在讀取及執行 const 作業一 hash_map 儲存。

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

備註

在 Visual C++ .NET Pocket PC, <hash_map><hash_set> 標頭檔 (Header File) 的成員不在 std 命名空間,,而是移至 stdext 命名空間。如需詳細資訊,請參閱 stdext 命名空間

範例

// 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;
}
  
  

需求

標題: <hash_map>

命名空間: stdext

請參閱

參考

hash_map Class

標準樣板程式庫