文件名称:c++ event示例
文件大小:22KB
文件格式:ZIP
更新时间:2017-12-18 03:30:16
c++ event listener
If you want to create a C++ class that calls clients' functions (events), you can do that in two ways. The first way is to call a global function through a function pointer that is a private member of your class. The client has to set that function pointer if it wants to handle that event. So, your class has two constructors, one with a function pointer and the other without it. If the client wants to handle an event, it has to create an instance of your class with the constructor that has a function pointer as the argument. The second way is to call a class member function of the client class through the interface that is provided with your class package. The client has to inherit that interface and implement an event function if it wants to handle that event. So, your class has two constructors, one with an event interface pointer and the other without it. If the client wants to handle an event, it has to create an instance of your class with the constructor that has a function pointer as the argument; for example, "CEvent(this)". Here is the code for both ways。
【文件预览】:
CPP_Events
----ClassEventHandler()
--------ClassWithEvents.h(405B)
--------ClassWithEvents.cpp(560B)
--------CPP_EVENTS.plg(1KB)
--------CPP_EVENTS.ncb(65KB)
--------CPP_EVENTS.dsp(4KB)
--------CPP_EVENTS.dsw(543B)
--------CPP_EVENTS.CPP(536B)
--------CPP_EVENTS.opt(53KB)
----GlobalEventHandler()
--------ClassWithEvents.h(297B)
--------ClassWithEvents.cpp(451B)
--------CPP_EVENTS.plg(1KB)
--------CPP_EVENTS.ncb(57KB)
--------CPP_EVENTS.dsp(4KB)
--------CPP_EVENTS.dsw(543B)
--------CPP_EVENTS.CPP(271B)
--------CPP_EVENTS.opt(53KB)