备注
此 API 已过时。替代为 unordered_map 类。
const 提供对元素的引用类型。读取和执行 const 操作的一 hash_map 存储。
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::const_reference const_reference;
备注
在Visual C++ .NET 2003中,成员<hash_map> 和 <hash_set> 头文件不再在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