I have trouble figuring out how to access bject method through array of pointers to objects.
I have an env object of Environment class:
Environment env;
My Environment has some object pointers as well as a dynamic array of pointers:
static Robot *robot;
static Obstacle *obstacle;
static Object **objects;
So inside objects I can have robots and obstacles:
But now when I want to access a method of an object in the objects array, how can I do that? I tried
Environment env;
Robot *robot;
robot = env.objects[0];
robot->setSpeed(175);
But it didn't work. I got an error:
error: invalid conversion from ‘Object*’ to ‘Robot*’
What am I doing wrong?
PS: Robot inherits from Object.
Thank you in advance!
Robotinherit fromObject?