Closed filimonic closed 1 year ago
attach() variant with passing payload to callback
Problem: When creating bot as a part of some class, unable to pass instance of class to callback function
class ControlTGBot : IControl { private: FastBot _bot; void _messageCb(FB_msg& msg) {...} public: void start() { _bot.attach(_messageCb); // Broken } }
Solution: Overload attach() method as void attach(void (*handler)(FB_msg& msg, void* payload), void* payload)
void attach(void (*handler)(FB_msg& msg, void* payload), void* payload)
class ControlTGBot : IControl { private: FastBot _bot; static void _messageCb(FB_msg& msg, void * control) {...} public: void start() { _bot.attach(_messageCb, this); } }
attach() variant with passing payload to callback
Problem: When creating bot as a part of some class, unable to pass instance of class to callback function
Solution: Overload attach() method as
void attach(void (*handler)(FB_msg& msg, void* payload), void* payload)