2

私はstruct特性を示すを持っています:

template<typename T>
struct FooTraits
{
    static const NEbool s_implementsFoo = false;
};

そして、私はそれをクラスで専門化することができます、したがって:

class Apple {};

template<>
struct FooTraits< Apple >
{
   static const NEbool s_implementsFoo = true;
}; 

ただし、現在FooTraits、専門にしたいクラスもテンプレート化されている場合は使用できません。したがって、次のようになります。

template< typename T >
class Fruit {};

template<>
struct FooTraits< Fruit >
{
   static const NEbool s_implementsFoo = true;
}; 

この最後のコードブロックをどのように表現すればよいのFruit< T >でしょs_implementsFoo = trueうか。

現在、次のエラーが報告されています。

error C3203: 'Fruit' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
error C2955: 'Fruit' : use of class template requires template argument list
    see declaration of 'Fruit'
error C2990: 'FooTraits' : non-class template has already been declared as a class template
    see declaration of 'FooTraits'
4

1 に答える 1

3

もともと私が書いたのFooTraitsは、テンプレート化された引数に依存しないので、脳のおならに気付く前になぜテンプレートを入れたのか。それは反対票とコメントです

あなたはこれができますか?私のマシンでコンパイルしています

template<typename T>
struct FooTraits< Fruit<T> >
{
    static const NEbool s_implementsFoo = true;
};
于 2010-10-12T14:35:48.333 に答える