I am trying to make a basic synchronous task scheduler in C++ for my application.The way I am thinking to do this is to treat every task as a Task object, and then the TaskScheduler can operate on them rather than handling multiple types.
class Task {
public:
Task( ... ? /* some sort of callback function stored in the task which is called at a later time*/) {}
virtual void Execute() = 0;
}
The Task will be responsible for storing what happens on each task and I am thinking to pass a function to either the constructor of the Task object, or the execution but here is where I am stuck.
For example if I had two tasks IntegerTask : Task and StringTask : Task and their callback functions looked like func(int, int, int) and func(std::string) respectively.
How can I pass these functions to the base task when the arguments might differ in lengths and the types of each parameter may change depending on which task has been created?
I don't want the TaskScheduler to be coupled with anything outside of its class, as such it should be able to operate on its own without any dependencies. Please ask if there is any clarification needed, I tried to explain as best as I could. Is this even possible in C++ or is there a better solution for what I am trying to achieve?