1

I have the following, rather simple, template:

template< typename T >
struct compare {
  bool operator()( T a, T b ) { return a < b; }
};

template< typename T, typename Comp = compare< T > >
T min( T a, T b ) {                                  // line 22
  Comp comp;
  if( comp( a, b ) ) return a;
  return b;
}

template< typename T, typename Comp = compare< T > >
T max( T a, T b ) {                                  // line 29
  Comp comp;
  if( !comp( a, b ) ) return a;
  return b;
}

When I compile the previous code I get the following errors:

utility.h:22: error: default template arguments may not be used in function templates
utility.h:29: error: default template arguments may not be used in function templates

I have written before many templates like this, much more complicated, but it's the first time I get this error. What am I doing wrong? Thanks in advance.

4

0 回答 0