Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct BaseHandler {}; //Blank class
- typedef void (BaseHandler::*InstantFunc)();
- struct MyDrivedClass : public BaseHandler {
- char *m_someMember;
- void DoJob() {
- printf("%s\n", m_someMember);
- }
- virtual void qq() {
- printf("!");
- }
- };
- class ForCallback {
- public:
- ForCallback(BaseHandler* handler, InstantFunc callback)
- : m_handler(handler), m_callback(callback) {}
- void Handle() {
- (m_handler->*(m_callback))();
- }
- protected:
- BaseHandler* m_handler;
- InstantFunc m_callback;
- };
- int main() {
- MyDrivedClass *drived = new MyDrivedClass();
- drived->m_someMember = "ololo";
- drived->qq();
- ForCallback *cBack = new ForCallback(drived, static_cast<InstantFunc>(&MyDrivedClass::DoJob));
- cBack->Handle();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement