Explanation why copy constructors are called when custom objects are map values
Wed Apr 14 2021 17:20:27 GMT+0000 (Coordinated Universal Time)
Saved by @wowza12341
1. Person("Bob", 45) is passed by value to make_pair(), so it is coped. 3. map::insert() makes a copy of its arguments before storing them. Explanation form: STL containers always make copies of any data that is stored in them. The reason is that the original data could go out of scope at any time, without the container knowing about it. The only way for the container to have valid data is to make its own copy. Simple form: STL Containers make a copy of the original data that is in them. That is why copy constructors are used.
https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688264#questions/4676330
Comments