Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>IEventListener::messageArrived</code> is overloaded, so the compiler can't determine the type of <code>&amp;IEventListener::messageArrived</code>. It could be <code>void (IEventListener::*)(Message*)</code> or <code>void (IEventListener::*)(ClientHandle*, Message*)</code>.</p> <p>The straighforward (and ugly) solution is to explicitely cast <code>&amp;IEventListener::messageArrived</code> to the desired type at the call site, like this:</p> <pre><code>emit(static_cast&lt;void (IEventListener::*)(Message*)&gt;(&amp;IEventListener::messageArrived), a_message_ptr); </code></pre> <p>or by assigning to a variable of the desired function type:</p> <pre><code>void (IEventListener::*func_ptr)(Message*) = &amp;IEventListener::messageArrived; emit(func_ptr, a_message_ptr); </code></pre> <p>(Did I say it was ugly?)</p> <p>The template parameter could also be explicitly specified:</p> <pre><code>emit&lt;void (IEventListener::*)(Message*)&gt;(&amp;IEventListener::messageArrived, a_message_ptr); </code></pre> <p>(Still ugly)</p> <p>Another imperfect solution is to deduce the type of <code>Signal</code> from the type of the listener (<code>T</code>) and the other parameters:</p> <pre><code>// Warning: untested. // For illustration purposes only template&lt;class T&gt; class ActionListener { public: //... void emit(void (T::*signal)()); template&lt;class Arg1T&gt; void emit(void (T::*signal)(Arg1T), Arg1T); template&lt;class Arg1T, class Arg2T&gt; void emit(void (T::*signal)(Arg1T, Arg2T), Arg1T, Arg2T); }; </code></pre> <p>This is imperfect though because the arguments types must match exactly.</p> <p>Depending how much change you can make in the design, a simpler solution would be to remove the ambiguity by giving different names to the members of IEventListener. You could also use an already existing signals/slots library, like <a href="http://www.boost.org/doc/libs/1_40_0/doc/html/signals2.html" rel="nofollow noreferrer">Boost.Signals2</a></p>
 

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