title: Calling a template method on a class template parameter
body: <p>The following minimal example put in a .cpp file causes a compiler error in VisualStudio 2017 (15.7.4, with /std:c++17 enabled):</p>
  
  <pre><code>template &lt;typename T&gt;
  class A
  {
      void f(T&amp; t)
      {
          t.g&lt;2&gt;();
      }
  };
  
  // B is a candidate for the template parameter T in A
  struct B {
      template &lt;int a&gt;
      void g() {
          // nothing here
      }
  };
  </code></pre>
  
  <p>The compiler error refers to the body of A::f() and reads:</p>
  
  <pre><code>error C2760: syntax error: unexpected token ')', expected 'expression' .
  </code></pre>
  
  <p>Note that neither A nor B are actually instantiated. The same error also occurs without declaring B. </p>
  
  <p>However, if I switch the order in which A and B are declared, the example compiles (and A can be instantiated). This is surprising, because I have not expressed any relation between A and B in the code. Another surprising fact is that adding an argument (e.g. an int) to the signature of B::g() and the call of g() also seems to solve the error (without changing the order of declaration).</p>
  
  <p>My questions are:
  (1) Why does the code above produce a compiler error?
  (2) How I can resolve it in a clean way?</p>