PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Examples/php/callback/example.h

#
C++ Header | 22 lines | 16 code | 5 blank | 1 comment | 1 complexity | f2aeaadad8e4d8daef380d67dd9cffc2 MD5 | raw file
 1/* File : example.h */
 2
 3#include <iostream>
 4
 5class Callback {
 6public:
 7	virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
 8	virtual void run() { std::cout << "Callback::run()" << std::endl; }
 9};
10
11
12class Caller {
13private:
14	Callback *_callback;
15public:
16	Caller(): _callback(0) {}
17	~Caller() { delCallback(); }
18	void delCallback() { delete _callback; _callback = 0; }
19	void setCallback(Callback *cb) { delCallback(); _callback = cb; }
20	void call() { if (_callback) _callback->run(); }
21};
22