g++ - pred

Martin Sebor sebor@roguewave.com
Sat Mar 17 20:16:00 GMT 2001


Maciej Hrebien wrote:
> 
> Hello again,
> 
> Please look at this:
> 
> template<class T>
> struct Pre
> {
>    void operator()(const T&, const T&){}
>    static void op(const T&, const T&){}
> };
> 
> template<class T, class PreT=Pre<T> >
                          ^^^^^^^^^^^

Function templates don't allow default template arguments.

> void fun(const T& a, const T& b)
> {
>    PreT::p(a,b);
> }
> 
> main()
  ^^^^^^

Missing return type.

> {
>    fun(1,2);
>    return 0;
> }
> 
> Why g++-2.95.2 gives me errors telling that I have default arg for template
> param
> if function template (PreT,fun)? I know that, I wrote it :) ISO/IEC 14882 p.
> 14.1 says that it should work.

You didn't read far enough, 14.1, p9 says it shouldn't:

"A default template-argument shall not be specified in a function template
declaration or a function template definition, ..."

Regards
Martin



More information about the Gcc-bugs mailing list