We are two students and we now have an epic big problem that we can't resolve. We asked our teacher for some help but he can't help us, so our last chance is this forum!
We're doing a project: a command interpreter of NPI files.
map<string,void(Interpreteur::*)()>::iterator trouve = interpreteur.myMap.find(saisie);
if(trouve == interpreteur.myMap.end())
cerr<<"command not found"<<endl;
else
(trouve->*second)();
We must use the object named "map" but we can't get the second parameter, named.. "Second". Why? Code Blocks told us the error is in the "else", here is the error:
'second' was not declared in this scope.
We have tried too:
map<string,void(Interpreteur::*)()>::iterator trouve = interpreteur.myMap.find(saisie);
if(trouve == interpreteur.myMap.end())
cerr<<"command not found"<<endl;
else
(trouve.second)();
And code blocks answered:
error: 'std::map, void (Interpreteur::*)()>::iterator' has no member named 'second'
If someone can help us, it will save our project, we must end it for tomorrow.. We will be very grateful.
Thank you very much for help, we can answer questions, if there are any :)
Refers to the first ( const ) element of the pair object pointed to by the iterator - i.e. it refers to a key in the map. Instead, the expression: i->second.
To get the first element of a Map , use destructuring assignment, e.g. const [firstKey] = map. keys() and const [firstValue] = map. values() . The keys() and values() methods return an iterator object that contains the Map's keys and values.
A std::map
iterator points to a pair. So to access the pair's second element, do this:
trouve->second
Note that in your case, the type of that second element is "pointer to member function of Interpreteur
," so to call it, you need to provide an Interpreteur
object. Something like this:
(interpreteur.*(trouve->second))()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With