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 回答