0
Cuatom class | unordered map | map
Hi Please refer code below : 1. Why temporary object on map causes Constructor Copy contructor two times ? One constructor and one copy contructor (to copy from main to map data) is ok but why third ? Refer objects m1 and um1 in example code. 2. What's the need of reserve on unordered_map ? Isnt hash alone is enough ? What role reserve plays ? Reserve on vector is ok but why for unordered_map ? 3. Why object m2 and um2 calls different number of special functions (unlike m1 and m2 calls same nos.)? https://code.sololearn.com/c3Ac0scIcKmn/?ref=app
2 Antworten
+ 2
1.try building the map element "in place" with emplace(), like this, to avoid creating first a pair :
map<int,test> m1;
m1.emplace(1,test())
to answer your second question i will refer you to a well explained post in stack overflow: https://stackoverflow.com/questions/42373232/why-does-stdunordered-map-have-a-reserve-method
I don't understand your 3rd question, i'm sorry (i am kinda in a rush today in real life 😅, sorry but maybe someone can explain better )
+ 1
Thanks