Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong></p> <p>OK, I've figured out your problem. It is the non-reference version of the <code>operator==</code>. It makes the <code>operator==</code> ambiguous. Simply remove it (as I originally suggested) and it'll work fine.</p> <hr> <p><strong>EDIT:</strong></p> <p>In response to your edit, you should still remove the first version of the <code>operator==</code> There is no need to make a copy of the object in question and then compare it. The second <code>operator==</code> looks reasonable and should work. Is there anything else you are leaving out?</p> <hr> <p><strong>EDIT:</strong></p> <p>The following compiles just fine for me using g++ 4.4.1:</p> <pre><code>#include &lt;iostream&gt; struct DistinctWord { DistinctWord(const std::string &amp;s) : strWord(s){} bool operator==(const DistinctWord&amp; W) const { return strWord == W.strWord; } std::string strWord; }; int main() { DistinctWord* wordOne = new DistinctWord("Test"); DistinctWord* wordTwo = new DistinctWord("Test"); if(*wordOne == *wordTwo) std::cout &lt;&lt; "true"; else std::cout &lt;&lt; "false"; } </code></pre> <p>If you are still having problems, then you are not showing all relevant code...</p> <hr> <p>First of all, where is the definition for <code>DistinctWord</code> and how does it relate to <code>Word</code>?</p> <p>Beyond that, you should do this:</p> <pre><code>bool Word::operator==(const Word&amp; W) const { return strWord == W.strWord; } </code></pre> <p>and just remove the two <code>operator==</code>'s you currently have. The first is making a copy then comparing which is silly, and your second is comparing a modifiable reference and always returning true which doesn't really serve any purpose.</p> <p>This one should work fine.</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