function template specialization problem

Andrew Haley aph@redhat.com
Tue Mar 21 19:47:00 GMT 2006


rodolfo@rodsoft.org writes:
 > Hi, I don't know if this is a C++ or g++ problem, but this snippet
 > doesn't compile, but I think it should:
 > 
 > template <class T> void test(const char *par);
 > 
 > template <> void test<int>(const char *par = 0) {}
 > 
 > int main()
 > {
 >     test<int>();
 > }
 > 
 > g++ 3.4.5 returns the following errors:
 > test.cpp:3: error: default arguments are only permitted for function parameters
 > test.cpp:7: error: no matching function for call to `test()'
 > 
 > Well, the first error text is a little bit misleading because I'm
 > defining a default argument for a function parameter, but somehow this
 > is not parsed correctly, and g++ thinks it's not a function.
 > 
 > So, is this allowed in c++ or is a g++ parse bug?

No.  See Section 14.7.3, Para. 21.

"Default function arguments shall not be specified in the explicit
specialization of a function template."

Andrew.



More information about the Gcc-help mailing list