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

前端 未结 2 1654
抹茶落季
抹茶落季 2021-01-23 00:16

I am using TRI DDS - here is the prototype for the function I am trying to call:

template
dds::sub::cond::ReadCondition::Re         


        
相关标签:
2条回答
  • 2021-01-23 00:38

    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?

    0 讨论(0)
  • 2021-01-23 00:55

    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(); });
    
    0 讨论(0)
提交回复
热议问题