#include #include #include #include class Interface { public: Interface() { }; void write(uint8_t val) { std::cout << "called Interface::write()" << std::endl; }; private: }; class Driver { public: using cb_t = void (*)(uint8_t); //typedef void(*cb_t)(uint8_t); Driver(cb_t cb) : cb(cb) { }; void do_something() { cb(50); cb(40); }; private: cb_t cb; }; template using CallbackObjectMethod = void(T::*)(uint8_t v); //template //void libFunctionObjectMethod(CallbackObjectMethod cbMethod, T* pFO) //{ // int val = 3; // (pFO->*cbMethod)(val); //} int main(void) { //using namespace std::placeholders; // for _1, _2, ... std::cout << "callback_example" << std::endl; Interface iface; iface.write(1); //Driver driv([](uint8_t a){ std::cout << a << std::endl;}); Driver driv([iface.this](uint8_t a) -> void { this->write(a);}); driv.do_something(); return 0; }