使用C++0x function & bind实现的事件
#pragma once #include
测试代码:
#include "stdafx.h" #include "Event.h" #include <iostream> class TestA { public: void handler(void* sender, char* e) { std::cout<<"TestA.Handler\r\n"; } }; class TestB { public: event OnEvent; void Raise(char* str) { OnEvent(NULL, str); } }; int _tmain(int argc, _TCHAR* argv[]) { TestA a; TestB b; b.OnEvent += delegate(&a, &TestA::handler); b.Raise(); system("PAUSE"); return 0; }