Store Function Pointers to any Member Function

前端 未结 4 1548
太阳男子
太阳男子 2020-12-30 16:59

My Event Manager

For a event manager I need to store many pointers to functions in a vector to call them when the event is triggered. (I will provide the source co

4条回答
  •  别那么骄傲
    2020-12-30 17:22

    You will have to use std::function. This is the only way to achieve a generic callback. As soon as you involve function pointers instead of function objects, it is not generic, will never be generic, and can never be made to be generic.

    unordered_map>>
    

    Function pointers are bad and should never be explicitly used in C++, only passed to templates like std::bind and std::function's constructor, and member function pointers are even worse.

提交回复
热议问题