Rename the virtual tick() override in PelicanTimer to doExpired() and give the base Timer class a non-virtual tick() that checks for expiration and dispatches to doExpired(). The exercise starting point now matches SolutionEx22. Co-authored-by: Qwen 3.8 27B <qwen3.8_27b-q3_k_xl@lmstudio.local>
24 lines
398 B
C++
24 lines
398 B
C++
|
|
|
|
#include "Timer.h"
|
|
#include "TimerSet.h"
|
|
|
|
void Timer::timeoutRequest(int seconds) { timeToGo = seconds; }
|
|
|
|
Timer::Timer() : timeToGo(-1) { TimerSet::Instance().addATimer(this); }
|
|
|
|
void Timer::tick() {
|
|
if (isExpired()) {
|
|
doExpired();
|
|
}
|
|
}
|
|
|
|
bool Timer::isExpired() {
|
|
if (timeToGo > 0) {
|
|
if (--timeToGo == 0) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|