Указание шаблонного класса с чертами - PullRequest
2 голосов
/ 12 октября 2010

У меня есть 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'

1 Ответ

3 голосов
/ 12 октября 2010

Изначально я писал, что FooTraits не зависит от шаблонного аргумента, так зачем вставлять шаблон, прежде чем я понял, что мой мозг пердит. Это даунвот и комментарии

Ты можешь сделать это? Он компилируется на моей машине

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