Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

Guru Question

  1. 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:

    1. Stylistic choices that could be improved to make the design better for more idiomatic C++ usage.

    2. Mechanical limitations that restrict the usefulness of the facility.

template < class T, void (T::*F)() >
class callback
 callback(T& t) : object(t) {}        // assign actual object to T
   void execute() {(object.*F)();}      // launch callback function
   T& object;
  • + Share This
  • 🔖 Save To Your Account