|
|
If m is a map,
Map<K,V> n = m;
will create a new map n whose elements are logical copies of the elements of m (that is, the result of applying operator=). The default value for subsequently created elements of n will be the same as for m. The same effect can be obtained by writing:
Map<K,V> n(m);
If m and n are maps with the same key and value types, then:
m = n;
effectively discards all the elements of m and creates new elements that are logical copies of all the elements of n. This does not change the default value for subsequently created elements of m; the value, if any, given when m was created remains.
One consequence of this is that passing a map as a function argument copies all the elements of the map. This preserves the normal call-by-value semantics of C++ but may have unexpected performance consequences. Consider writing functions whose arguments are references to maps instead of maps themselves.