#ifndef MT2Q7_H #define MT2Q7_H /////////////////////////////////////////////////////////////// // MT2Q7.h - Callback // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2012 // /////////////////////////////////////////////////////////////// #include #include #include class Widget { public: void f(const std::string& s) { std::cout << "\n been called with string \"" << s.c_str() << "\""; } }; template class Invoker { public: typedef void (T::*fptr)(const std::string&); // first important part typedef std::pair elem; void subscribe(T* pT, fptr f) // client must pass object ref and func ptr { elem e; e.first = pT; e.second = f; commands.push_back(e); } void invoke(const std::string& s) { for(size_t i=0; i commands; }; #endif