![]() |
---|
此 API 已过时。另一种方法是 unordered_multimap Class。 |
提供对元素的类型在 hash_multimap 存储状态。
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::reference reference;
备注
在 Visual C++ .NET 2003 中,<hash_map> 和 <hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间。
示例
// hash_multimap_reference.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_multimap <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 as the
// non-const_reference cannot be used to access the key
// int &Ref1 = ( hm1.begin( ) -> first );
cout << "The key of first element in the hash_multimap 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 first element in the hash_multimap is "
<< Ref2 << "." << endl;
//The non-const_reference can be used to modify the
//data value of the first element
Ref2 = Ref2 + 5;
cout << "The modified data value of first element is "
<< Ref2 << "." << endl;
}
要求
标头: <hash_map>
命名空间: stdext