function template specialization problem

Daniel Llorens del Río
Tue Mar 21 22:10:00 GMT 2006

On 21 Mar, 2006, at 20:16, wrote:

> 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()'

The first error message is unclear, but the code is illegal anyway.  
You cannot declare a default parameter in a specialization. You must  
declare it in the function template declaration, and only there.

More information about the Gcc-help mailing list