I would like to know how to fill this type of map and mainly the way to access to the function pointer.
The map :
enum enum1
{
val11,
val12,
val13
};
enum enum2
{
val21,
val22,
val23
};
typedef void(MyClass::*funcPtr)();
std::map<std::pair<enum1, enum2>, funcPtr> map;
I fill it like this, it seems to work:
map.insert(std::make_pair(std::make_pair(val11, val21), &MyClass::init));
But I can't access to the function like this:
map[std::make_pair<val11, val21>]();
What am I doing wrong?
You are using the wrong parentheses with make_pair
and need to call the member function on some instance of MyClass
(using the .*
or ->*
operators):
MyClass obj;
(obj.*map[std::make_pair(val11, val21)])();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.