Code:
class Dispatcher
{
//Dispatcher callback.
template<typename T>
using DispatchCallback = std::function<void(T&)>;
public:
//Constructor.
Dispatcher(Event &e)
{
m_event = e;
}
//Dispatch.
template<typename T>
void Dispatch(DispatchCallback<T> callback)
{
//Call the callback function.
if (m_event.GetType() == T::GetStaticType())
callback( *(T *)&m_event );
}
private:
Event m_event;
};
In the code above, when the Dispatcher() constructor gets called the m_event = e; does not work. The copy constructor of e is not getting called.
Is this an expected behavior? I know that when you pass references the idea is that the copy constructor does not get called but I thought that this only works when you assign a reference to another reference like this:
Code:
//Copy Constructor should not get called here.
Event &new_ref = other_reference;
But when you do something like this:
Code:
//Copy Constructor should be called here, isn't it?
Event new_event = other_reference;