我有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'
答案 0 :(得分:3)
最初我写道,FooTraits
并不依赖于模板化的论证,所以为什么在我意识到我的大脑放屁之前放入模板。这是downvote和评论
template<typename T>
struct FooTraits< Fruit<T> >
{
static const NEbool s_implementsFoo = true;
};