You store copies of the listeners instead of pointers to them. Worse, you don't even store full copies, but just the EventListener part of them. This is called object slicing: http://en.wikipedia.org/wiki/Object_slicing
It should work if you only changed these three lines (and object.addCustomListener(&listener);).
However, note that with your current approach DataClass will never know when one of the listeners has been destroyed.
Also, the EventListener destructor should be virtual. If it isn't, deleting a derived listener via a EventListener pointer would result in undefined behavior.
// eventlistener.h
#include <iostream>
#include "customevent.h"
usingnamespace std;
class EventListener
{
public:
EventListener(){};
~EventListener(){}
virtualvoid action(CustomEvent*){} // the changed line
}
In dataclass.h, I now have this:
1 2 3 4 5 6 7 8 9
void fireListeners()
{
CustomEvent event; // added line
list<EventListener>::iterator it;
for(it=listeners.begin(); it!=listeners.end(); it++)
{
(*it).action(&event); // changed line
}
}
My problem: CustomEvent cannot find DataClass. If I include dataclass.h in customevent.h, then it won´t compile because DataClass includes customeventlistener.h which in turn includes customevent.h. So the three files includes each other in a circle-like manner.