c++ - Address operator with pointer to member function -
we know create "common" pointer function can example:
void fun(); void (*ptr)() = fun;
the name of function address function start. not need use address operator & this:
void (*ptr)() = &fun;
now pointer member function on contrary must use address operator. example class pointer member function ptr , function fun() must write:
void(a::*ptr)() = &a::fun;
why difference?
it because function defined inside class. pointer member function holds "relative address" of function in class layout , have access way.
in case of static, has no pointer , behaves global function , so, can access normal function pointer.
Comments
Post a Comment