I can choose between function pointers and subclass objects. To make it clear, say that I must notify some object of some action (for example, a timer); refer to the following two options (very simple code for demo purposes):
Version 1
typedef void TimerCallback(void *args); class Timer{ public: Timer(); ~Timer(); void schedule(TimerCallback *callback, void *args, long timeout)=0; void cancel(); };
Version 2
class TimerTask{ public: TimerTask(); virtual ~TimerTask(); void timedout()=0; }; class Timer{ public: Timer(); virtual ~Timer(); void schedule(TimerTask *callback, long timeout)=0; void cancel(); };
which one is the standard C ++ way and which one is effective? Please let me know if you have any other suggestions in this regard.
Please let me know if I do not understand in this regard.
thanks
source share