I need an array that stores unique objects, and preferably, I would like to store Super-class instances of the Sub - class of what the array was made for... this is the code I have so far:
The reason why I need this is so that I can loop through the items in the array (not literally looping, looping in an abstract way) to update motors and such and such (I would be using this code for a robot)
#include <iostream>
class Task
{
public:
int UpdateTask()
{
//to be overriden by superclass.
}
};
class SuperTask: Task;
{
private:
float SomeInputVariable;
bool Wait;
public:
SuperTask(float some_input_variable, bool wait = true)
{
SomeInputVariable = some_input_variable;
Wait = wait;
//the constructor would mainly be for setting values.
}
int UpdateTask()
{
if (SomeExitCondition)
{
//stop motors etc.
return -1;
//0 will be the excape value.
}
//update motors etc.
if (Wait)
{
return 0;
// 1 will be the value that tells the loop to not go any further
// until this task is done (returns 0)
}
return 1;
};
Task Tasks[] = {
SuperTask t1(100, true),
};
int main()
{
while(true)
{
//do some looping stuff.
//here I would need to call the UpdateTask() method on each task.
}
}
and right where I declare t1, visual studio (2019) says "type name not allowed"
I am unsure how to accomplish what I am trying to do, is there a way to do what I am trying to do that will work?