如果您需要在专门模板会很尴尬的情况下执行此操作,您还可以计算类型以与一些适当的模板一起使用:
template<class T> struct remove_all_pointers {
typedef T type;
};
template<class T> struct remove_all_pointers<T*> {
typedef typename remove_all_pointers<T>::type type;
};
template<class T> struct remove_all_pointers<T* const> {
typedef typename remove_all_pointers<T>::type type;
};
template<class T> struct remove_all_pointers<T* volatile> {
typedef typename remove_all_pointers<T>::type type;
};
template<class T> struct remove_all_pointers<T* const volatile> {
typedef typename remove_all_pointers<T>::type type;
};
struct Foo {
typedef int inner_type;
};
template<class T>
struct Bar {
typename remove_all_pointers<T>::type::inner_type x;
};