Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplated "Listener" handler ambiguity problem
    text
    copied!<p>I'm using JUCE as a x-platform framework, and I'm using template listener classes to map button/combobox etc. callbacks to certain handler functions. Since the different widgets have their own callback function name, I use the following structure:</p> <pre><code>template&lt;typename Type, typename Widget&gt; class ListenerBase : public Widget::Listener { public: typedef void (Type::*TCallbackType)(void); protected: void notifyCallback(Widget* notifier) { ... } void addHandler(Widget* notifier, TCallbackType callback) { notifier-&gt;addListener(this); ... } }; template&lt;typename Type&gt; class ButtonListenerHandler : public ListenerBase&lt;Type, Button&gt; { protected: void buttonClicked(Button* btn) { notifyCallback(btn); } }; template&lt;typename Type&gt; class LabelListenerHandler : public ListenerBase&lt;Type, Label&gt; { protected: void labelTextChanged(Label* lbl) { notifyCallback(lbl); } }; </code></pre> <p>And it works fine, as long as I use only one of the handler specializations in my class. As soon as I use more than one, VC++ 2008 complains of ambiguity between the addHandler calls as if the compiler cannot distiguish between addHandler(Button*, ...) and addHandler(Label*, ...) !! These functions are of different prototypes due to being templatized, so I have no idea why the compiler is giving me a hard time. Ideas ?</p> <p>Edit due to requests:</p> <p>A class with different listeners may look like:</p> <pre><code>class MyClass : public ButtonListenerHandler&lt;MyClass&gt; , public LabelListenerHandler&lt;MyClass&gt; { ... void buttonHandlerFunction(); void labelHandlerFunction(); Button* m_btn; Label* m_label; }; </code></pre> <p>A where the error occurs:</p> <pre><code>MyClass::MyClass() { ... addHandler(m_btn, &amp;MyClass::buttonHandlerFunction); &lt;&lt;&lt; error addHandler(m_label, &amp;MyClass::labelHandlerFunction); &lt;&lt;&lt; error } </code></pre> <p>And the error is:</p> <pre><code>1&gt;MyClass.cpp(287) : error C2385: ambiguous access of 'addHandler' 1&gt; could be the 'addHandler' in base 'ListenerBase&lt;MyClass,juce::Button&gt;' 1&gt; or could be the 'addHandler' in base 'ListenerBase&lt;MyClass,juce::Label&gt;' </code></pre>
 

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