利用模板偏特化判断类型是否是指针 :
#include<iostream>
using namespace std;
template <typename T>
struct TraitsHelper {
static const bool isPointer = false;
};
template <typename T>
struct TraitsHelper<T*> {
static const bool isPointer = true;
};
int main() {
cout << TraitsHelper<int>::isPointer << endl;
cout << TraitsHelper<int*>::isPointer << endl;
}