class CMyClass
{
public:
CMyClass()
{
mm.insert(make_pair(1,&CMyClass::func1));
func2();
}
typedef void (CMyClass::*func)();//mark
protected:
void func1();
void func2();
protected:
map<int, func> mm;
};
void CMyClass::func1()
{
cout<<"func1"<<endl;
}
void CMyClass::func2()
{
// 成员函数的指针一定要用某个对象来调用
// 不用指针调用的话,编译报错 类似error C2064: 项不会计算为接受 0 个参数的函数
map<int, func>::iterator iter = mm.find(1);
(this->*(*iter).second)();
(this->*mm[1])();
}