Let’s say I have a globally scoped set defined as follows:
std::set<Person> people;
I’ve a function where I create an instance of the class Person
, and add it to the set as follows:
void addEntry() {
Person p1("kosh", 55);
people.emplace(p1);
}
The way I understand it, a copy of the object will be created (I can see the copy constructor getting called) and added to the set. Once this function terminates, p1
goes out of scope. But, what is the scope of the copy that is added to the set? Is that determined by the scope of the set?