I would love create javascript's setTimeout and setInterval like functionality for c++ (without boost). What I would like to achieve: A base class which could call its sub-classed member variables at a repeated or after a single delay.
I have an update function already and time elapsed functionality. I have also found how to pass a member function pointer to the base class and trigger that function using:
class BaseClass {
public:
template <class object>
void triggerNow(object *obj, void (object::*func)()) {
((obj)->*(func))();
}
}
class SubClass : public BaseClass {
public:
void update() {
triggerNow(this, &SubClass::worked)
}
void worked() {
cout << "worked!";
}
}
The problem I currently face is how to store object *obj and void (object::*func)() in a vector (or other container). I am only just figuring out templates...
How can I store the two templated parameters of triggerNow in a vector? Once I can figure this out, I can create my setTimeout and setInterval!
std::vector<void (object::*)()> theVectorinstance variable, then have a look at how Foundation's legendaryNSTimerclass does the thing (though that is Objective-C, the C parts will match :)