title: Operator overload resolution work within namespaces
body: <pre><code>namespace A{
     struct A{
      inline void operator+(const int B) {};   // 1)
   };
      inline void operator+(const A&amp; a,const int B) {};  // 2)
   }
  
      inline void operator+(const A::A&amp; a,const int B) {};  // 3)
  
  int main()
  {
   A::A a;
   a+1; // compile questions
   return 1;
  }
  </code></pre>
  
  <p>The above codes can be compiled without any problem.</p>
  
  <p>But if 1) is commented, it fails to be compiled due to "ambiguous overload for 'operator+' in 'a + 1'" at 2) and 3). I can understand that the operator+ is first searched in class, there is the reason if 1) is not commented, no problem to be compiled. Aren't I right? </p>
  
  <p>Main question: If 1) is commented, why compiler has found one matched operator+, it continues to find the others? I am also curious that which one should be found first as well. (I thought it should stopped immediately based on the information <a href="https://stackoverflow.com/questions/11359562/how-does-the-operator-overload-resolution-work-within-namespaces">How does the operator overload resolution work within namespaces?</a>)</p>
  
  <p><strong>Second questions:</strong></p>
  
  <pre><code>namespace A{
     struct A{
      inline void operator+(const long int B) {};   // 4), the input parameter type has been changed to long int
   };
      inline void operator+(const A&amp; a,const int B) {};  // 5)
      void test();
   }
  
      inline void operator+(const A::A&amp; a,const int B) {};  // 6)
  
   void A::test()
   {
      A a; // a)
      a+ 1; 
   }
  
  
  int main()
  {
   A::A a;
   a+1;  // b) 
   return 1;
  }
  </code></pre>
  
  <p>Compilation ambiguous error at a) due to 4) and 5).</p>
  
  <p>Compilation ambiguous error at b) due to 4) ,5) and 6).</p>
  
  <p>Question i)</p>
  
  <p>For a) and b) , why compiler has already found operator+ with (const long int input parameter type ) at 4), which is member operator funciton in struct A, it still keeps going to find out others. In my mind, compiler should stopped there gives out the type error information. It should be the same as in the case the memeber fucntion's input parameter type is exactly matched, it stops searching for others.</p>
  
  <p>Question 2)</p>
  
  <p>I thought the compiler should stop at 4) and give out type error information.
  In the case it continues, why member function overloading function (long int) has the same resolution ranking as non-memmber with exact matched input parameter ?  In this case, I thought the non-member case with exact matched input parameter should win if compiler decides to continue searching, which makes more sense.</p>