C++ How do you pass a member function into a functor parameter?

可紊 提交于 2019-12-02 03:54:48

You can use a lambda function with a capture.

dds::sub::cond::ReadCondition rc(*mp_reader,
                                 dds::sub::status::DataState::any(),
                                 [this](){ this->do_stuff(); });

You could use std::bind (see http://en.cppreference.com/w/cpp/utility/functional/bind)

dds::sub::cond::ReadCondition rc(*mp_reader,
                                 dds::sub::status::DataState::any(),
                                 std::bind(&MyClass::do_stuff, this));

See also How to directly bind a member function to an std::function in Visual Studio 11?

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