I have some Object structs that look like this:
struct Object {
string type;
Color c;
float ambient, diffuse;
};
struct Sphere: Object {
Point center;
float radius;
};
struct Square: Object {
Point loc;
float len;
};
And I have a vector that is filled with Sphere and Square structs:
vector<Object> objs;
Sphere sp = //sphere stuff
Square sq = //square stuff
objs.push_back(sp);
objs.push_back(sq);
I can access the values in the parent struct just fine, but I am having trouble figuring out how to access the values in the Sphere and Square structs. This is what I am doing right now:
cout << objs.at(i).type << endl; //This works
cout << objs.at(i).center.x << endl; //Not working
Does anyone know how to do this?