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

前端 未结 4 1473
北海茫月
北海茫月 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 08:11

    About static member function guarantees:

    С++ ISO/IEC 14882 2003-10-15 says that

    5.2.2 There are two kinds of function call: ordinary function call and member function 57) (9.3) call....

    57) A static member function (9.4) is an ordinary function.

    Theoretically static-member-functions can have another calling convention. But standart allow us to leverage on such thing...

    Answer: typedef void (Person::*PPMF2)() => typedef void (*PPMF2)()

提交回复
热议问题