次のかなり単純なテンプレートがあります。
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;
}
前のコードをコンパイルすると、次のエラーが発生します。
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
私はこのような多くのテンプレートの前に、はるかに複雑に書いてきましたが、このエラーが発生したのは初めてです. 私は何を間違っていますか?前もって感謝します。