Below is my code, wanted to know what does the line my_map[1] = std::set<int*>();
serve?
std::map<int, std::set<int *>> my_map;
int main() {
int i = 10;
int *ptr = &i;
my_map[1] = std::set<int *>();
my_map[1].insert(ptr);
for (std::map<int, std::set<int *>>::const_iterator it = my_map.begin();
it != my_map.end(); it++) {
cout << it->first << "-->";
for (std::set<int *>::const_iterator itt = it->second.begin();
itt != it->second.end(); itt++) {
cout << *(*itt) << "\t";
}
cout << endl;
}
cout << "Hello World";
return 0;
}
As said it creates an empty set and assigns it to
my_map[1]
.However, it's not needed. If no element exists for a key, then accessing that key with
[]
will create a default-constructed data-element.This code:
is enough.