devxlogo

A Pointer to Member Cannot Refer to a Static Member Function

A Pointer to Member Cannot Refer to a Static Member Function

It is illegal to assign the address of a static class member to a pointer to member. However, you can take the address of a static member function of a class and treat it as if it were an external function:

 class A { public:	static  void f();};void main() {	void (*p) () = &A::f; //OK, p is an ordinary pointer to function}

The secret here is that a static member function is actually an ordinary global function, whose class serves as a namespace.

devx-admin

Share the Post: