Determine if a class has a function
Using a trick (described by Olivier Langlois ) I can tell if a class is of a specific type:
template<typename T> struct hasType
{
template<typename C> static char test( typename C::Type );
template<typename C> static char* test(...);
enum{ Value= sizeof(test<T>(0))==1 };
};
I can also tell if a class has a variable:
template<typename T> struct hasType
{
template<typename C> static char test( decltype(C::var) );
template<typename C> static char* test(...);
enum{ Value= sizeof(test<T>(0))==1 };
};
However, decltype(c::func)
nur decltype(c::func())
(which depends on parameters) does not work for member functions . Is there a way to do this, or do I need to create a functor in each class and detect it using typename C::functor
?
Edit : You are both correct, but since I also have to test for the type, I will use decltype(&C::func)
(which obviously needs to be a pointer).
source to share
No one has answered this question yet
See similar questions:
or similar: