How to define a function pointer pointing to a static member function?

前端 未结 4 1505
北海茫月
北海茫月 2021-01-17 07:49
#include \"stdafx.h\"

class Person;
typedef void (Person::*PPMF)();

// error C2159: more than one storage class specified
typedef static void (Person::*PPMF2)();           


        
4条回答
  •  渐次进展
    2021-01-17 07:58

    A pointer to a static member function is just a normal function pointer. typedef void (*PPMF2)(). You assign it to a static member function like you assign any function pointer, only that the static member function is inside the class scope:

    PPMF2 myfunc = &MyClass::StaticMemberFunc;
    

提交回复
热议问题