我的窗口库需要一个事件系统,但我不能传递模板lambdas,存储它们并稍后使用。
窗口类
template<typename ...Args> void SetCallback(EventType type, void(*callback)(Args...)) { m_Callbacks[type] = callback; } template<typename ...Args> void CallCallback(EventType type, Args&&... args) { m_Callbacks[type](std::forward<Args>(args)...); } protected: bool m_ShouldClose; std::unordered_map<EventType, void*> m_Callbacks;
实例
window->SetCallback(Ale::EventType::KeyEvent, [](int a, int b) { // Do things here }); // Another location window->CallCallback(Ale::EventType::KeyEvent)(0, 60);
我在这工作,但什么都不管用,我超级困惑。