title: Overloading operator<< for enum class inside template class
body: <p>I can't seem to be able to overload <code>operator&lt;&lt;</code> for an enum class inside a template class:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  struct S
  {
      enum class E { A, B };
  
      E e;
  };
  
  template &lt;typename T&gt;
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; s, const typename S&lt;T&gt;::E e)
  {
      return s &lt;&lt; static_cast&lt;int&gt;(e);
  }
  
  int main()
  {
      const S&lt;int&gt; s {};
      std::cerr &lt;&lt; s.e;    // error
  }
  </code></pre>
  
  <p>The exact error message produced by Visual Studio 2015 is:</p>
  
  <pre><code>error C2679: binary '&lt;&lt;': no operator found which takes a right-hand operand of type 'const S&lt;int&gt;::E' (or there is no acceptable conversion)
  </code></pre>
  
  <p>Both gcc and clang fail with a similar error message.</p>
  
  <p>Two notes:</p>
  
  <ul>
  <li>If I change the enum class to a plain enum, the code compiles fine.</li>
  <li>If I specialize the <code>operator&lt;&lt;</code> overload for <code>T = int</code>, the code compiles fine as well.</li>
  </ul>
  
  <p>What am I missing?</p>