boost::bind and class member function

夙愿已清 提交于 2019-12-03 06:10:15

You were really, really close:

void calc(int x) {
    std::for_each(v.begin(), v.end(),
        boost::bind(&foo::func2, this, _1, x));
}

EDIT: oops, so was I. heh.

Although, on reflection, there is nothing really wrong with your first working example. You should really favour free functions over member functions where possible - you can see the increased simplicity in your version.

While using boost::bind for binding class member functions, the second argument must supply the object context. So your code will work when the second argument is this

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!