F
feverzsj
i wrote a template to test whether a type is a class type.
but i find that using an ordinary member function "test()" will cause
compiler error like"no qualified name for pointer to member".
what's the difference in this place???
template<typename T>
class ClassChecker{
typedef char One;
typedef struct{char _c[2];} Two;
template<typename C> static One test(int C::*);
template<typename C> static Two test(...);
public:
enum{YES = sizeof(test<T>(0))==1};
enum{NO = !YES};
};
template<typename T>
void CheckClass()
{
if( ClassChecker<T>::YES )
cout<<"type '"<<typeid(T).name()<<"' IS a Class type"<<endl;
else
cout<<"type '"<<typeid(T).name()<<"' IS NOT a Class type"<<endl;
}
but i find that using an ordinary member function "test()" will cause
compiler error like"no qualified name for pointer to member".
what's the difference in this place???
template<typename T>
class ClassChecker{
typedef char One;
typedef struct{char _c[2];} Two;
template<typename C> static One test(int C::*);
template<typename C> static Two test(...);
public:
enum{YES = sizeof(test<T>(0))==1};
enum{NO = !YES};
};
template<typename T>
void CheckClass()
{
if( ClassChecker<T>::YES )
cout<<"type '"<<typeid(T).name()<<"' IS a Class type"<<endl;
else
cout<<"type '"<<typeid(T).name()<<"' IS NOT a Class type"<<endl;
}