Reputation: 13575
For example
template<class T>
struct Foo
{
typedef int Type;
void f();
}
Foo<T>::f()
can be specialized for a specific T
. How about the defined type Type
? If it works, I don't need to specialize the whole class. Any ways to implement this intent?
Upvotes: 1
Views: 56
Reputation: 45434
template<class T>
struct Foo
{
typedef typename some_class_template<T>::type Type;
void f();
};
member functions have declaration and definition and you can specialise the definition. That cannot be done for member types. These must be specialised with their declaration.
Of course, my some_class_template
can be anything from the standard library, for example
typedef typename std::conditional<sizeof(T)==4, int, T>::type Type;
Upvotes: 2