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'
因爲這是特質類如何工作? '性狀 :: IsInt == true'但特性 :: IsInt == false' –
tenpn
2010-10-12 14:39:05
@tenpn是的,我意識到,當我回到我自己的項目並鍵入unary_function ... – wheaties 2010-10-12 14:47:30
可能發誓我試過了那!謝謝 :) – dukedave 2010-10-12 14:49:24