0
我只是想将一个lambda函数传递给一个回调函数。我正在使用std::function
进行回调。我需要传递数据到这个函数,这是我遇到问题的地方。下面的错误代码中的代码“无法转换为预期类型”。目标是在SDL
的事件中使用回调。我不确定这是否是正确的做法。我将回调函数存储在unordered_map
中,密钥为SDL_Event.type
和vector
的std::function
。对于SDL事件回调,使用lambda错误的std :: function
我在设置中调用了事件轮询中的dispatch()
和subscribe
。在subscribe()
拉姆达
// main.cpp
window->subscribe(SDL_KEYDOWN, [](SDL_Event& ev) -> void {
std::cout << "key pressed" << std::endl;
});
// eventhandler.cpp
void EventHandler::subscribe(int _event, std::function<void(const SDL_Event&)> _callback)
{
m_callbacks[_event].push_back(_callback);
}