#include #include #include using namespace std;template class TEvent{public:class Handler{public:Handler(){registry.push_back(this);}virtual int handleEvent(const T& t) = 0;};static void notify (TEvent* t);void Notify(){T::notify(this);}typedef list HandlerList;private:static
HandlerList registry;};template void TEvent::notify (TEvent* t){typename HandlerList::iterator i;for(i = registry.begin(); i != registry.end(); i ++){(*i)->handleEvent(* (T*) t);}}template typename TEvent::HandlerList TEvent::registry;class CoinInsertedEvent
: public TEvent{};class CoinReleaseEvent : public TEvent{};class ProductDispenseEvent : public TEvent {};class CoinChanger:public CoinReleaseEvent :: Handler,public ProductDispenseEvent :: Handler{public:int handleEvent(const ProductDispenseEvent& event){cout<<"changer::
coin dispensed"<<endl;return 0;}int handleEvent(const CoinReleaseEvent& event){cout<<"changer:: coin released"<<endl;return 0;}};int main(){CoinReleaseEvent coinReleaseEvent;CoinChanger coinChanger;ProductDispenseEvent productDispenseEvent;coinReleaseEvent.Notify();productDispenseEvent.Notify();}