Parse err, for template function with explicit type-parameter in a class

Peter Nordlund petern@nada.kth.se
Thu Jul 2 05:02:00 GMT 1998


I think that the code which is commented out below 
is correct and should compile.

The function aT() works ok. 

If the same code is declared inside a class I get a 
parse error, see At::a3T() and At::a4T().

Putting the function in a namespace works ok, see NS::a3T()

//Peter
----------
>>g++ -v
Reading specs from
/misc/cvap/egcs/egcs-19980628/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.43/specs
gcc version egcs-2.91.43 19980628 (gcc2 ss-980502 experimental)

-----------------------------------------------------------
#include <iostream>

template <class T> // Ok
T aT() { return T(1.5); }

class At {
public: 
  static int a2() { return (2); } // Ok
  template <class T> // should work but doesn't
    static T a3T() { return T(3.5); }  
  template <class T> // should work but doesn't
    T a4T() { return T(4.5); }
  int a5T() { return (5); } // Ok
};

namespace NS { 
  int a2() { return (2); } // Ok
  template <class T> // Ok, here similar construction works!
    T a3T() { return T(3.5); }
};

typedef int testT;

int main() {
  testT t = aT<testT>(); // Ok
  testT t2 = At::a2();   // Ok (should really be)
  cerr << "t:" << t << " t2:" << t2 << endl;
  //testT t3 = At::a3T<testT>();//err.cc:29: parse error before `>'
  testT t3 = NS::a3T<testT>(); // Ok
  //testT t4 = At().a4T<testT>();//err.cc:31: parse error before `>'
  testT t5 = At().a5T(); // Ok (should really be)
  cerr << "t3:" << t3 << " t5:" << t5 <<endl;
  return 0;
}



More information about the Gcc-bugs mailing list