Note that there are some explanatory texts on larger screens.

plurals
  1. POdefining hash in tr1 for a template class
    primarykey
    data
    text
    <p>I have the class Gateway. I need to store object of this class in a hash table (using tr1::unordered_set). I've used both the unorderd_set and the class Gateway in another context and they work fine, yet I can't figure how to put a gateway in a unordered set because I can't define its <code>hash</code> function in tr1's namespace.</p> <p>I've tried: (and many other variants)</p> <pre><code>namespace std { namespace tr1 { template&lt;&gt; &lt;typename T&gt; inline size_t hash&lt;(typename Gateway&lt;T&gt;)&gt;::operator()(Gateway&lt;T&gt; gT) const { return gT.getCore()-&gt;hash(); //!DOESN't WORK } } </code></pre> <p>The compiler says the this (<code>typename Gateway&lt;T&gt;</code>) is wrong. If i take the <code>()</code> off, it assumes the <code>&gt;&gt;</code> in the end of <code>hash&lt;typename Gateway&lt;T&gt;&gt;()</code> is the output stream.</p> <p>While in the past i've done this</p> <pre><code>namespace std { namespace tr1 { template&lt;&gt; inline size_t hash&lt;Board&gt;::operator()(Board b) const { return b.hash(); //!WORKS FINE } } } </code></pre> <p>Can anyone shed some light on the problem?</p> <p><strong>Update</strong></p> <p>Thanks for the answer yet there is still a problem The compiler says invalid use of incomplete type <code>struct std::tr1::hash&lt;&gt;</code></p> <p>This sort of error happens when we use the class without its complete definition, yet the class is fully defined before the declaration. I've already used this without templates in a very similar fashion without a problem.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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