I need to create and array of DIFFERENT kinds of objects. For instance, in Java, I can do something like this ...
// scene objects
Sphere scene_sphere = new Sphere();
Plane scene_plane = new Plane();
Object[] scene_objects = {scene_sphere, scene_plane};
in my program, both the Sphere class and the Plane class have a method called findIntersection(ray), which do different things, but both return a float, and then I can loop through my scene objects and call the method on any object in the array like this ...
Object[] intersections;
for (int index = 0; index < scene_objects.length(); index++) {
intersections[index] = scene_objects[index].findIntersection(ray);
}
So far, with c++, all I know how to do is create a super class called Object and make both the Sphere and Plane classes inherit from the Object class. The problem is, when I loop through my scene objects and call the findIntersection method, I get an error saying that the Object class doesn't have a method called findIntersection. So how do I pass the findIntersection call on to the Sphere or Plane? I've already tried something like this ...
class Object {
public:
// default constructor, no arguments
Object ();
float findIntersection(Ray ray) {
return this.findIntersection(ray);
}
};
But this doesn't work of course. Any help would be appreciated. Thanks.