Note that there are some explanatory texts on larger screens.

plurals
  1. POrequest for member `...' is ambiguous in g++
    text
    copied!<p>I'm getting the following compile error in one of my classes, using gcc 3.4.5 (mingw): </p> <pre><code>src/ModelTester/CModelTesterGui.cpp:1308: error: request for member `addListener' is ambiguous include/utility/ISource.h:26: error: candidates are: void utility::ISource&lt;T&gt;::addListener(utility::IListener&lt;T&gt;*) [with T = const SConsolePacket&amp;] include/utility/ISource.h:26: error: void utility::ISource&lt;T&gt;::addListener(utility::IListener&lt;T&gt;*) [with T = const SControlPacket&amp;] </code></pre> <p>Hopefully you can see that <code>ISource&lt;T&gt;</code> is a template interface that just indicates that the object can be an informer for an object that is of some matching type <code>IListener&lt;T&gt;</code>. So the thing that has me irked is this idea that for some reason functions are ambiguous when, as far as I can tell, they are not. The <code>addListener()</code> method is overloaded for different input types <code>IListener&lt;const SConsolePacket&amp;&gt;</code> and <code>IListener&lt;const SControlPacket&amp;&gt;</code>. The usage is:</p> <pre><code>m_controller-&gt;addListener( m_model ); </code></pre> <p>Where <code>m_model</code> is a pointer to an <code>IRigidBody</code> object, and <code>IRigidBody</code> inherits only from <code>IListener&lt; const SControlPacket&amp; &gt;</code> and definately not from <code>IListener&lt; const SConsolePacket&amp; &gt;</code></p> <p>As a sanity check, I used doxygen to generate the class hierarchy diagram and doxygen agrees with me that <code>IRigidBody</code> does not derive from <code>IListener&lt; const SConsolePacket&amp; &gt;</code></p> <p>Evidently my understanding of inheritence in c++ is not exactly correct. I'm under the impression that <code>IListener&lt;const SControlPacket&amp;&gt;</code> and <code>IListener&lt;const SConsolePacket&amp;&gt;</code> are two different types, and that the function declarations </p> <pre><code>addListener(IListener&lt;const SConsolePacket&amp;&gt;* listener) </code></pre> <p>and</p> <pre><code>addListener(IListener&lt;const SControlPacket&amp;&gt;* listener) </code></pre> <p>declare two separate functions that do two separate things depending on the (distinct) different type of the parameter that is input. Furthermore, I'm under the impression that a pointer to an <code>IRigidBody</code> is also a pointer to an <code>IListener&lt;const SControlPacket&amp;&gt;</code> and that by calling <code>addListener( m_model )</code> the compiler should understand that I'm calling the second of the above two functions.</p> <p>I even tried casting <code>m_model</code> like this:</p> <pre><code>m_controller-&gt;addListener( static_cast&lt;IListener&lt;const SControlPacket&amp;&gt;*&gt;(m_model) ); </code></pre> <p>but still get that error. I cannot for the life of me see how these functions are ambiguous. Can anyone shed light on this issue?</p> <p>P.S. I know how to force the function to be un-ambiguous by doing this:</p> <pre><code>m_controller-&gt;ISource&lt;const SControlPacket&amp;&gt;::addListener( m_model ); </code></pre> <p>I just happen to think that is terribly unreadible and I would prefer not to have to do that.</p> <p>Edit... just kidding. That apparently doesn't fix the problem as it leads to a linker error:</p> <pre><code>CModelTesterGui.cpp:1312: undefined reference to `utility::ISource&lt;aerobat::SControlPacket const&amp;&gt;::addListener(utility::IListener&lt;SControlPacket const&amp;&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