Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to be careful when you use <strong>friend</strong> and <strong>template</strong></p> <pre><code>#include&lt;iostream&gt; #include&lt;map&gt; template &lt;class T&gt; class MyHash{ public: // ... use your T template here template &lt;class U&gt; friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const MyHash&lt;U&gt; &amp;rhs); }; // ... template &lt;class U&gt; ostream&amp; operator&lt;&lt;(ostream&amp; out, const MyHash&lt;U&gt; &amp;rhs){ return out &lt;&lt; "test"; } </code></pre> <p>you need to use a different <strong>template U</strong> because <strong>operator&lt;&lt;</strong> is a <strong>friend</strong> method (external), if we use <strong>T</strong> instead of <strong>U</strong>, we will have : <strong>ambiguous definition in template </strong>.</p> <p>Change <strong>hash</strong> by <strong>MyHash</strong> to avoid ambiguities.</p> <p><strong>Edit :</strong> </p> <p>The error that you get <a href="https://github.com/everett1992/couple-solver/tree/master/test_dir" rel="nofollow">here</a> is :</p> <blockquote> <p>error C2676: '&lt;' binaire : 'std::string' ne définit pas cet opérateur ou une conversion vers un type acceptable pour l'opérateur prédéfini</p> </blockquote> <p>because you forgot to include <code>&lt;string&gt;</code> in <strong>"hash.h"</strong>. That header defines the <strong>&lt; operator</strong>. </p> <p>And also try moving the definition of <strong>operator[]</strong> and <strong>operator&lt;&lt;</strong> directly into <strong>"hash.h"</strong> Both the declaration and definition of templates must be included. This is because in some compilers template functions cannot be compiled and linked independently, since they are generated on request for the specific types they are instantiated with.</p> <p>Change the <strong>#include "hash.cpp"</strong> to <strong>#include "hash.h"</strong></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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