This chapter is from the book
Guru Question
-
The following code presents an interesting and genuinely useful idiom for wrapping callback functions. For a more detailed explanation, see the original article. [Kalev01]
Critique this code and identify:
-
Stylistic choices that could be improved to make the design better for more idiomatic C++ usage.
-
Mechanical limitations that restrict the usefulness of the facility.
-
template < class T, void (T::*F)() > class callback { public: callback(T& t) : object(t) {} // assign actual object to T void execute() {(object.*F)();} // launch callback function private: T& object; };