I have an Ellipsoid struct, which is a derivative of the Object struct. Basically, I want to make an Object[3][13] pointer array in a Scene struct, in which I can point to different Object derivatives.
struct Ellipsoid : public Object {
//...
}
In the main function:
Ellipsoid ellipsoids[13];
addEllipsoids(3, ellipsoids); // this fills the array with valid ellipsoids, everything seems to be fine up until this point
// printing the contents here, everything is good
scene.addObjects(ellipsoids);
After printing the "ellipsoids" array here, everything seems nice.
in the Scene struct:
struct Scene{
int arr_num;
Object* objects[3];
void addObjects(Object* o){
// printning the o[0], o[1], ... contents here, getting garbage..
objects[arr_num++] = o;
}
When I print out the *o contents here (from 0..12) even before I add them to the objects array, I get nasty memory garbage results.
This is for homework and I can't use std::vector and such things, only very basic stuff. I really have no idea what is the problem here.