C++ How to pass member function pointer to another class?

后端 未结 2 2058
-上瘾入骨i
-上瘾入骨i 2020-12-19 15:22

Here is what I want to realize:

class Delegate
{
public:
    void SetFunction(void(*fun)());
private:
    void(*mEventFunction)();
}

Then i

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 15:39

    You should pass &Test::OnEventStarted, this is the right syntax for a member function pointer

    And after that, you'll have to get an instance of the Test class to run the function like this

    instanceOfTest->*mEventFunction()

提交回复
热议问题