The problem of searching from a list card

In my program, I have a map with string keys and a list (of a user-defined class) with values ​​defined like this:

std::map<const char*, std::list<Show>> _shows;

I have a function that adds to a specific list, for example:

void Add(Show s, const char* index) {
list<Show> lshow = _shows[index];
lshow.push_back(s); }

However, every time a function is called with the same index, instead of returning the same list, I get an empty list.

What am I doing wrong?

ETA: I see that the number of values ​​in the dictionary increases after each function call. Could this be the [] operator associated?

+3
source share
5 answers

- , . . , std::string. , . ,

list<Show>& ls = map[index]
+6

:

list<Show>& lshow = _shows[index];

.

, , . , , operator[].

( , ) std::string .

+1

const char * std:: map. , . , :

std::map<std::string,std::list<Show> >
+1

list<Show> lshow = _shows[index], , . , : list<Show> &lshow = _shows[index].

0

lshow _shows[index]. _shows[index].push_back(s), _shows[index] :

std::list<Show> &lshow = _shows[index];
lshow.push_back(s);

_shows, , , .

0

Source: https://habr.com/ru/post/1773610/


All Articles