Using generic std::function objects with member functions in one class

前端 未结 6 2191
遥遥无期
遥遥无期 2020-11-22 09:41

For one class I want to store some function pointers to member functions of the same class in one map storing std::function objects. But I fail rig

6条回答
  •  深忆病人
    2020-11-22 10:29

    Either you need

    std::function f = &Foo::doSomething;
    

    so that you can call it on any instance, or you need to bind a specific instance, for example this

    std::function f = std::bind(&Foo::doSomething, this);
    

提交回复
热议问题