次の方法で共有


hash_multimap::const_reference

[!メモ]

この API は、互換性のために残されています。代わりに unordered_multimap クラスです。

[const] の要素への参照を提供する型は [const] 操作を読み取りと操作実行のために格納されているhash_multimap

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

解説

Visual C++ .NET 2003では、<hash_map><hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。

使用例

// hash_multimap_const_ref.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 because 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 1st element in the hash_multimap is "
        << Ref2 << "." << endl;
}
  
  

必要条件

ヘッダー: <hash_map>

名前空間: のstdext

参照

関連項目

hash_multimap Class

標準テンプレート ライブラリ