title: function template overloading - ordering
body: <p>I don't get it. I know function templates are evil, but in this case we have to use it. So this is not the matter. We have an archive that uses a template-operator-function. The specialisation for objects/vale types follows after the template function declaration/definition:</p>
  
  <pre><code>class BaseArchive
  {
  public:
      BaseArchive() {}
      virtual ~BaseArchive();
  
      template&lt; typename T &gt;
      BaseArchive &amp; operator&lt;&lt;(const T &amp;t)
      {
          ::operator&lt;&lt;(*this, t);
          return *this;
      }
  };
  
  BaseArchive &amp; operator&lt;&lt;(BaseArchive &amp;ar, const int &amp; i)
  {
      return ar;
  }
  
  class StdArchive : public BaseArchive
  {
  public:
      StdArchive();
  
      template&lt; typename T &gt;
      StdArchive &amp; operator&lt;&lt;(const T &amp;t)
      {
          ::operator&lt;&lt;(*this, t);
          return *this;
      }
  };
  
  int main()
  {
      BaseArchive ar;
      int i = 7;
      ar &lt;&lt; i;
  }
  </code></pre>
  
  <p>For this example we get an error:</p>
  
  <p><strong>::operator&lt;&lt; has not been declared</strong></p>
  
  <p>This one can be fixed by a forward declaration of </p>
  
  <pre><code>class BaseArchive;
  BaseArchive &amp; operator&lt;&lt;(BaseArchive &amp;ar, const int &amp; i);
  
  class Archive { ...
  </code></pre>
  
  <p>So far so good. But afterwards some classes define their own ::operator for the archive and thus it hard or even not possible to ensure that the specific operator declaration occurs always before the archive-header-include nor even we want to use an global operator inlcude file.</p>
  
  <p>Any idea how to solve this and/or a explanation why this error occurs? As usual the VS-compiler soesn't care about that, but the minGW (gcc) compiler does...</p>
  
  <p>many thanks </p>