In my program, I have a map with string keys and list (of a user-defined class) values, defined like so:
std::map<const char*, std::list<Show>> _shows;
I have a function that adds to a specific list, like so:
void Add(Show s, const char* index) {
list<Show> lshow = _shows[index];
lshow.push_back(s); }
However, every time the function is called with the same index, rather than returning the same list, I get an empty list.
What am I doing wrong?
ETA: I see the number of values in the dictionary increases after each time I call the function. Could this be [] operator related?
The key in your map is the pointer value, not its contents. Therefore weird behavior. Change the map so that its key be
std::string. Also, you modify the copy of your stored list. To avoid this, use a reference