mercredi 20 février 2019

STL map - no matching constructor

I have a std map that combines a string with a function pointer like:

 std::map<std::string, void (*)()> funcs {
       {"print", &h::print},
       {"scan", &h::scan_cmd},
       {"connect", &h::stream},
       {"stream", &h::stream}
 };

where h is the enclosing class in which this map has been initialized. I get this error:

No matching constructor for initialization of 'std::map<std::string, void (*)()>' (aka 'map<basic_string<char>, void (*)()>')

I've also tried puttting the map in this form:

std::map<std::string, void (*)()> funcs;
funcs["print"] = &print;
funcs["scan"] = &scan_cmd;
funcs[connect"] = &stream;
funcs["stream"] = &stream;

But then I got this error:

Size of array has non-integer type ' const char [6]'

I'm not exactly sure where the problem is - my guess is that it's with the void (*) () portion.

Aucun commentaire:

Enregistrer un commentaire