The compiler is telling you what is going on at the end of the message:
(source type is not polymorphic)
Your Event
base class needs to have at least one virtual
member function (i.e. be a polymorphic type) in order to allow dynamic casts. You could make the destructor of Event
virtual:
class Event
{
public:
virtual ~Event() { /* whatever goes here, or nothing... */ }
// ...
};
Here is a live example with polymorphic types, showing that the code compiles (removing the virtual destructor would cause a compilation error similar to the one you are seeing).
As correctly mentioned by Luc Danton in the comments, a defaulted version of a virtual destructor can be defined this way (if your compiler is C++11-compliant in this respect):
class Event
{
public:
virtual ~Event() = default;
// ...
};