首页 新闻 会员 周边

成员函数有返回值为什么与没有返回值的绑定方式不一样?(C++)

0
悬赏园豆:10 [已关闭问题] 关闭于 2016-12-01 16:14

function<void(int)> void_fn;

function<int(int)> int_fn;

struct foo

{

  void vmf(int){}

  int imf(int){return 0;}

};

 

void_fn = bind(&foo::vmf, new A);// OK

int_fn = bind(&foo::imf, new A);// Error

 

请给个解决方案

fyter的主页 fyter | 初学一级 | 园豆:172
提问于:2016-11-27 19:04
< >
分享
所有回答(1)
0

templete<typename type, typename memfn>

function<int(int)> bindmf(memfn fn, type obj){return bind(fn, obj, _1);}

 

这就可以绑定了,但不知道原因。

fyter | 园豆:172 (初学一级) | 2016-12-01 16:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册