次のような関数のセットを考えてみましょう
template< class Fun >
void A( const Fun& )
{
}
template< class Fun >
void B( const Fun& )
{
}
template< class Fun >
void C( const Fun& )
{
}
関数型を引数として取るように設計されています。次に、これは完全に問題ありません。
template< class T >
void Func( const T& )
{
}
A( Func< int > );
B( Func< int > );
C( Func< int > );
int
今、私はtemaplate 引数の繰り返しを取り除きたかったので、これを試しました:
template< class T >
struct Helper
{
template< template< class > class Fun >
static void A( Fun< T >& f )
{
A( f );
}
template< template< class > class Fun >
static void B( Fun< T >& f )
{
B( f );
}
...
};
typedef Helper< int > IntHelper;
IntHelper::A( Func ); //error
IntHelper::B( Func ); //
IntHelper::C( Func ); //
ただし、これは gcc 4.5.1 ( 'error: no matching function for call to 'Helper<int>::A(<unresolved overloaded function type>)'
) および MSVC10 (cannot use function template 'void Func(const T &)' as a function argument
およびcould not deduce template argument for 'overloaded function type' from 'overloaded function type'
) ではコンパイルに失敗します。
誰かが理由を正確に説明できますか?これを回避する方法はありますか?
編集OK 今はできない理由がわかりました。回避策を含む回答の場合:実際のコードにはFunc
、たとえば100など、さまざまなsがたくさんありますが、A、B、Cなどの関数は約6つしかありません...