I was looking at the implementation of the is_class
template in Boost, and ran into some syntax I can\'t easily decipher.
template
You're right, it is analogous to a function pointer. Rather, this is a pointer to member function, where the member is of the class U
.
The difference in type is necessitated because member functions have an implicit this
pointer, as they cannot be called without an instance. Getting rid of the template might make it a bit easier:
struct foo
{
void bar(void);
};
void(*)(void)
won't do, as this has no way to communicate an instance of the class. Rather, we need:
void (foo::*)(void)
Indicating that this function pointer requires an instance of foo
.
For what it's worth, you use them like this:
typedef void (foo::*func_ptr)(void);
foo f;
foo* fp = &f;
func_ptr func = &foo::bar;
(f.*func)();
(fp->*func)();