title: Which takes precedence, the free function operator==() or the member function operator==()?
body: <p>When the free operator function and the member operator function are both defined, which one is used for comparison?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class A;
  class B;
  
  bool operator==(const A &amp;a, const B &amp;b){ return true; };
  
  class A
  {
    public:
        bool operator==( const B &amp;rhs ){ return false; };
  };
  
  class B
  {
  };
  
  int main( int argc, char **argv )
  {
    A a;
    B b;
    if( a == b )
    { 
        std::cout &lt;&lt; "a==b" &lt;&lt; std::endl;
    }
  };
  </code></pre>
  
  <p>I ran the code a couple times and it seems that the member operator wins out. Is this always the case?</p>