PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/octave/callback/example.h

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