C++ Call Pointer To Member Function

后端 未结 4 1228

I have a list of pointers to member functions but I am having a difficult time trying to call those functions... whats the proper syntax?

typedef void (Box::         


        
4条回答
  •  心在旅途
    2020-11-27 19:30

    From my "award winning" ;-) answer about delegates (available at https://stackoverflow.com/questions/9568150/what-is-a-c-delegate/9568226#9568226) :

    Typedef the pointer to member function like this:

    typedef void (T::*fn)( int anArg );
    

    Declare one like this:

    fn functionPtr = &MyClass::MyFunction
    

    Call it like this:

    (MyObject.*functionPtr)( argument );
    

提交回复
热议问题