Currently trying to implement an event handler for an SDL project. The general idea is that user input events will be handled via Message
objects, that will be able to carry around callbacks with different signatures.Currently, what I have is :
#pragma once
#include<functional>
#include"Entity.h"
#include"Enums.h"
typedef std::function<void(void)> VoidCallback;
typedef std::function<void(const Entity& entity)> EntityCallback;
template<typename Functor>
class Message
{
private:
MessageType message;
public:
Message(MessageType message, Functor callback) :message(message), callback(callback) {};
~Message();
};
However, this arrangement makes it difficult to pass different types of callbacks to different listeners. The current listener implementation is
#include"Message.h"
class Listener
{
public:
virtual void onNotify(Message<>& event) = 0;
};
which which causes errors. What would be the best way to resolve this issue?