Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have implemented a callback mechanism based on this article:</p> <p><a href="http://www.codeproject.com/KB/cpp/CPPCallback.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/cpp/CPPCallback.aspx</a></p> <p>With that implementation you can either use <em>global functions</em>, <em>static member functions</em> or <em>non-static member functions</em> as callbacks. </p> <p>The article describes how to create delegate objects as functors for all of these types. Your <code>class B</code> could have a delegate object as member and a method for registering a callback function and a method for calling it. Neither <code>class B</code> nor your callback functions have to be templated! The delegate objects contain an object pointer in case a non-static member function is used as callback and a pointer to a templated static wrapper function. In this wrapper function the function pointer to your callback function is stored. It is either invoked directly or before bound to the passed object pointer.</p> <pre><code>class B { public: void SetCallback(CDelegate f_Delegate) { m_Delegate = f_Delegate; } static void do_something() { //... m_Delegate(); //... } private: static CDelegate m_Delegate; }; </code></pre> <p><em>Update:</em></p> <p>The mechanism is also described here: <a href="https://stackoverflow.com/questions/4298408/5-years-later-is-there-something-better-than-the-fastest-possible-c-delegates">5 years later, is there something better than the &quot;Fastest Possible C++ Delegates&quot;?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload