Interview Question
Country: United States
It depends on the type of container. Some of them allow duplicate keys others donot.
Map does not allow duplicate keys.
So A is the key(not the val to be stored):
map<A, val1> and map<A, val2> would end in val2 being stored
If A is the value(not the key), then
map<key1, A> and map<key2, A> would result in two separate copies of A being stored in two separate places
Multimap, allows storage of duplicate keys.
New copies of Object would be created. Only in case of pointers the same object would be referred as only the pointer variable copy would be created.
- Som April 24, 2014