Good day. There is a class BssManager which has a functor and a method whose signature corresponds to the signature of this functor. How can I initialize the functor with this method in the initialization list of this class? Below is the code that I do not compile.

class BssManager { public: BssManager(); ..... void GetAndProcessBssPackage(const uint8_t in_data[], uint16_t in_length, BssPacketType in_type); ..... private: ..... std::function<void(const uint8_t*, uint16_t, BssPacketType)> get_and_process_bss_package_functor_; ..... }; BssManager::BssManager() : number_of_bss_(0) ..... , get_and_process_bss_package_functor_(std::bind(&GetAndProcessBssPackage, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)) { }; 

C ++ 14, GCC compiler, IDE MVS2017.

    1 answer 1

    To get a pointer to a class method, you should specify its name as a prefix:

     std::bind(&BssManager::GetAndProcessBssPackage, 
    • Hm I did it at the very beginning, it did not work. Now it worked. Looks like it was sealed somewhere. Thanks a lot for your help. - mrFieldy