title: C++ weird templates/namespaces behavior
body: <p>I had a problem compiling my code since it wasn't able to find a matching function on a template. I've narrowed down the problem to this example:</p>
  <pre><code>namespace cv
  {
      class FileNode
      { };
  
      template&lt;typename _Tp&gt; static inline void operator &gt;&gt; (const FileNode&amp; n, _Tp&amp; value)
      {
          read(n, value, _Tp());
      }
  
      static inline void read(const FileNode&amp; node, bool&amp; value, bool default_value)
      { }
  }
  
  class K
  {   };
  
  namespace D
  {
      class A
      { };
  }
  
  template&lt;class X&gt;
  static void read(const cv::FileNode&amp; node, X&amp; x, const X&amp; default_value)
  {
      return;
  }
  
  using namespace D;
  class B
  {
      void read(const cv::FileNode&amp; fn)
      {
          A a;
          fn &gt;&gt; a;
      }
  };
  
  int main(int argc, char* argv[]) { }
  </code></pre>
  <p>On Gcc 9.10 I get the following error:</p>
  <pre class="lang-none prettyprint-override"><code>invalid initialization of reference of type 'bool&amp;' from expression of type 'D::A'  { read(n, value, _Tp()); }
  </code></pre>
  <p>On Visual Studio 2019:</p>
  <pre class="lang-none prettyprint-override"><code>Error   C2664    'void cv::read(const cv::FileNode &amp;,bool &amp;,bool)': cannot convert argument 2 from '_Tp' to 'bool &amp;'
  </code></pre>
  <p>I've found any of the following changes will make the code compiling:</p>
  <ul>
  <li><code>class A</code> -&gt; <code>class A : public K</code></li>
  <li>Delete <code>read</code> specialization for <code>bool</code></li>
  <li>Remove <code>cv</code> namespace</li>
  <li>Move the <code>read</code> template inside namespace <code>D</code></li>
  </ul>
  <p>Unfortunately, none of the previous fixes is applicable to my original problem and I still don't really have an actual understanding on why exactly it's not able to find the <code>read</code> template.</p>