I have always read that you can define a trait like
enum MyEnum { val_1, val_2, val_3 };
template< typename T >
struct my_trait {
static const MyEnum value = MyEnum::val_1;
};
and then specialise it
template<>
struct my_trait < void >{
static const MyEnum value = val_3;
};
When I have tried it I always get a linker error since the static
member is not defined, so I have to explicitly specialise it in the source file as
MyEnum my_trait < void >::value = val_3;
and change the definition in the header to
template<>
struct is_void< void >{
static const MyEnum value;
};
Is there any way to define the trait directly in the header without having to redefine it in the header?