C++ 将字符串映射到函数

C++ 将字符串映射到函数,c++,map,C++,Map,我正试着这么做,但没用 这是我的错误: 必须使用“.”或“->”调用中成员函数的指针 “((test*)this)->test::mapping.std::map::operator[],void(test:*)(int),std::less>,std::分配器,void(test:*)(int)>>((const 键(U型)(&str))(…)”,例如“(…->”* ((test*)this)->test::mapping.std::map::operator[],void(test::*)(

我正试着这么做,但没用 这是我的错误:

必须使用“.”或“->”调用中成员函数的指针 “((test*)this)->test::mapping.std::map::operator[],void(test:*)(int),std::less>,std::分配器,void(test:*)(int)>>((const 键(U型)(&str))(…)”,例如“(…->”* ((test*)this)->test::mapping.std::map::operator[],void(test::*)(int),std::less>,std::分配器,void(test::*)(int)>>((const 键类型(&str))(…)'

test.h:
#包括。。。。
使用名称空间std;
课堂测试
{
公众:
地图映射;
无效添加(int);
};
test.cpp:
test::test()
{
映射[“添加”]=&测试::添加;
string str=“添加”;
这个。*映射[str](3);//不起作用!!!!
}
无效测试::添加(int a)
{

cout由于
这是一个指针,您需要使用
->*
而不是
*
。此外,还需要一些括号

(this->*mapping[str])(3);

在这个代码中有多个错误。你到底在用这个代码做什么?把C++移植到perl?@ didierc是必要的,因为标准是这样说的,正如在代码> [ExpR.Copy] P1<代码>中所说的。哦,对,它是指向这个实例的成员的指针。我没看到(膝关节反应反应要小心!)
(this->*mapping[str])(3);