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?
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.