title: specializing member S::display requires ‘template<>’ syntax
body: <p>I'm creating a trait class to help with my program. I have a template class called <code>operations</code> that contains the methods <code>display</code> and <code>area</code>. When I define these functions I get errors. Here they are:</p>
  
  <blockquote>
    <p>error: specializing member <code>‘traits::operations&lt;Rectangle&gt;::display’</code> requires <code>‘template&lt;&gt;’</code> syntax<br>
    error: specializing member <code>‘traits::operations&lt;Rectangle&gt;::area’</code> requires <code>‘template&lt;&gt;’</code> syntax</p>
  </blockquote>
  
  <p>As you can see, the compiler wants me to insert <code>template &lt;&gt;</code> just before those definitions. But when I do, I get a huge page of errors. What's going wrong and how can I fix it?</p>
  
  <p>Here is my program.</p>
  
  <pre><code>namespace traits
  {
      template &lt;typename P&gt;
      struct operations
      {
          static void display(Rectangle const &amp;, std::ostream &amp;);
          static void area(Rectangle const &amp;);
      };
  
      template &lt;typename P, int N&gt;
      struct access {};
  }
  
  namespace traits
  {
      template &lt;int N&gt;
      struct access&lt;Rectangle, N&gt;
      {
          static double get(Rectangle const &amp;);
      };
  }
  
  // The errors occur here
  namespace traits
  {
      static void operations&lt;Rectangle&gt;::display(Rectangle const &amp;rect, std::ostream &amp;os)
      {
          os &lt;&lt; rect.width  &lt;&lt; '\n';
          os &lt;&lt; rect.height &lt;&lt; '\n';
          os &lt;&lt; area(rect)  &lt;&lt; '\n'; 
      }
  
      static void operations&lt;Rectangle&gt;::area(Rectangle const&amp; rect)
      {
          double width =  get&lt;0&gt;(rect);
          double height = get&lt;1&gt;(rect);
  
          return width * height;
      }
  }
  
  namespace traits
  {
      template &lt;&gt;
      struct access&lt;Rectangle, 0&gt;
      {
          static double get(Rectangle const &amp;rect)
          {
              return rect.width;
          }
      };
  
      template &lt;&gt;
      struct access&lt;Rectangle, 1&gt;
      {
          static double get(Rectangle const &amp;rect)
          {
              return rect.height;
          }
      };
  }
  
  template &lt;int N, typename P&gt;
  static inline double get(P const &amp;p)
  {
      return traits::access&lt;P, N&gt;::get(p);
  }
  
  template &lt;typename P&gt;
  static inline void display(P const &amp;p)
  {
      traits::operations&lt;P&gt;::display(p, std::cout);
  }
  
  template &lt;typename P&gt;
  static inline double area(P const &amp;p)
  {
      return traits::operations&lt;P&gt;::area(p);
  }
  
  int main()
  {
  
  }
  </code></pre>
  
  <p>Here is a program which shows the error - <a href="http://ideone.com/WFlnb2#view_edit_box" rel="noreferrer">http://ideone.com/WFlnb2#view_edit_box</a></p>
  
  <p>Any and all help is appreciated.</p>
  
  <hr>
  
  <p>Thanks to help from the comments I got rid of those two errors, but I'm not getting more after adding the <code>template&lt;&gt;</code> declaration and fixing the return type of <code>area</code>:</p>
  
  <blockquote>
    <p>error: cannot declare member function <code>‘static void traits::operations&lt;P&gt;::display(const Rectangle&amp;, std::ostream&amp;) [with P = Rectangle; std::ostream = std::basic_ostream&lt;char&gt;]’</code> to have static linkage [-fpermissive]<br>
    error: explicit template specialization cannot have a storage class<br>
    error: specialization of <code>‘static double traits::operations&lt;P&gt;::area(const Rectangle&amp;) [with P = Rectangle]’</code> after instantiation<br>
    error: explicit template specialization cannot have a storage class</p>
  </blockquote>