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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -