共用方式為


hash_map::operator=

Replaces the elements of the hash_map with a copy of another hash_map.

hash_map& operator=(
   const hash_map& _Right
);
hash_map& operator=(
   hash_map&& _Right
);

Parameters

Parameter

Description

_Right

The hash_map Class being copied into the hash_map.

Remarks

After erasing any existing elements in a hash_map, operator= either copies or moves the contents of _Right into the hash_map.

Example

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

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_map<int, int> v1, v2, v3;
   hash_map<int, int>::iterator iter;

   v1.insert(pair<int, int>(1, 10));

   cout << "v1 = " ;
   for (iter = v1.begin(); iter != v1.end(); iter++)
      cout << iter->second << " ";
   cout << endl;

   v2 = v1;
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << iter->second << " ";
   cout << endl;

// move v1 into v2
   v2.clear();
   v2 = move(v1);
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << iter->second << " ";
   cout << endl;
}

Output

v1 = 10 
v2 = 10 
v2 = 10 

Requirements

Header: <hash_map>

Namespace: std

See Also

Reference

hash_map Class

Standard Template Library

Other Resources

hash_map Members