|
-
January 30th, 2010, 02:05 PM
#9
Re: How to check if template is a pointer?
You may create template function like this:
template <class T>
bool IsPointerType()
{
return strchr(typeid(T).name(), '*') != 0;
}
Then check if some type is pointer or not:
cout << IsPointerType<int>() << endl;
cout << IsPointerType<int*>() << endl;
In second case the answer is "1" (in first "0"). In your template class checking is similiar but
I suggest to do this in constructor and then set some flag:
SomeClass<T>::SomeClass()
{
// this is member flag variable of type bool
_isPointerType = IsPointerType<T>();
// rest of constructor stuff
}
Then you may query this flag to know if type is pointer or not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|