Aggregate initialization in C++

  aggregate, c++, forward, initialization

I have a base class Event, from which concrete events derive:

struct Event
{
};


struct CollisionEvent : Event
{
    //CollisionEvent(Entity entityA, Entity entityB) : entityA(entityA), entityB(entityB) {}

    Entity entityA;
    Entity entityB;
};

this class is a POD, and I should be able to perform aggregate initializaion. But the following code fails to compile:

called from application:

eventBus->DispatchEvent<CollisionEvent>(mEntities[i], mEntities[j]);



in EventBus.h:

template <typename TEvent, typename... Args>
    void DispatchEvent(Args&&... args)
    {
        auto it = mEventHandlers.find(typeid(TEvent));

        if (it != mEventHandlers.end())
            for (auto &&eventHandler : it->second)
                eventHandler->Invoke(TEvent{ std::forward<Args>(args)... });
    }

saying that it cannot convert initializer list to TEvent. Why?

Source: Windows Questions C++

LEAVE A COMMENT