2

I have a struct which indicates a trait:

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

And I can specialize it with a class, thus:

class Apple {};

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

However currently I cannot use FooTraits if the class I wish to specialize it on is also templatized, thus:

template< typename T >
class Fruit {};

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

How should I express this last block of code so any Fruit< T > has s_implementsFoo = true?

Currently the following errors are reported:

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'
Cœur
  • 37,241
  • 25
  • 195
  • 267
davetapley
  • 17,000
  • 12
  • 60
  • 86

1 Answers1

3

Originally I wrote, the FooTraits doesn't depend on the templated argument so why put in a template before I realized my brain fart. That's the downvote and the comments

Can you do this? It's compiling on my machine

template<typename T>
struct FooTraits< Fruit<T> >
{
    static const NEbool s_implementsFoo = true;
};
wheaties
  • 35,646
  • 15
  • 94
  • 131
  • 1
    Cuz that's how traits classes work? `Traits::IsInt == true` but `Traits::IsInt == false` – tenpn Oct 12 '10 at 14:39
  • @tenpn Yes, I realized that right after I went back to my own project and typed unary_function... – wheaties Oct 12 '10 at 14:47