6

を「プロトタイプが一致しない」:テンプレートの部分特殊化:私は部分的にuntemplatedクラスのテンプレートメンバ関数を特化しようとしている

#include <iostream> 

template<class T> 
class Foo {}; 

struct Bar { 

    template<class T> 
    int fct(T); 

}; 

template<class FloatT> 
int Bar::fct(Foo<FloatT>) {} 


int main() { 
    Bar bar; 
    Foo<float> arg; 
    std::cout << bar.fct(arg); 
} 

私は次のエラー取得しています:

c.cc:14: error: prototype for ‘int Bar::fct(Foo<FloatT>)’ does not match any in class ‘Bar’ 
c.cc:9: error: candidate is: template<class T> int Bar::fct(T) 

コンパイラエラーを修正するにはどうすればよいですか?

答えて

9

機能(メンバーまたはそれ以外)の部分的な特殊化は許可されていません。

利用の過負荷:

struct Bar { 

    template<class T> 
    int fct(T data); 

    template<class T> //this is overload, not [partial] specialization 
    int fct(Foo<T> data); 

}; 
関連する問題