您的位置:首页 > 其它

函数指针 成员函数指针

2015-12-05 18:41 176 查看
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])();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: