Guru of the Week #2 no match for the operator==
<p>From <a href="http://www.gotw.ca/gotw/002.htm" rel="nofollow">Guru of the Week #2</a>. We have the original function:</p>

<pre><code>string FindAddr( list&lt;Employee&gt; l, string name )
{
    for( list&lt;Employee&gt;::iterator i = l.begin(); // (1)
         i != l.end(); 
         i++ ) 
    {
        if( *i == name ) // (2)
        {
            return (*i).addr;
        }
    }
    return "";
}
</code></pre>

<p>I added dummy Employee class to that:</p>

<pre><code>class Employee
{
    string n;
public:
    string addr;

    Employee(string name) : n(name) {}
    Employee() {}

    string name() const
    {
        return n;
    }

    operator string()
    {
        return n;
    }
};
</code></pre>

<p>And got compilation error:</p>

<p>In place (1):</p>

<pre><code>conversion from ‘std::_List_const_iterator&lt;Employee&gt;’ to non-scalar type ‘std::_List_iterator&lt;Employee&gt;’ requested
</code></pre>

<p>In place (2):</p>

<pre><code>no match for ‘operator==’ in ‘i.std::_List_iterator&lt;_Tp&gt;::operator* [with _Tp = Employee]() == name’
</code></pre>

<p>To eliminate first one, we change <code>iterator</code> to <code>const_iterator</code>. And the only way to eliminate second error, is to write own operator==. <strong>However, Herb Sutter wrote that:</strong></p>

<blockquote>
  <p>The Employee class isn't shown, <strong>but for this to work it must either have a conversion to string or a conversion ctor taking a string</strong>.</p>
</blockquote>

<p>But Employee has a conversion function and conversion constructor. GCC version 4.4.3. Compiled normally, <code>g++ file.cpp</code> without any flags.</p>

<p>There should be implicit conversion and it should work, why it doesn't? I don't want operator==, I just want it work like Sutter said, with <em>a conversion to string or a conversion ctor taking a string</em>.</p>
