Let's say there is a class foo that has a variable of another class, call it C. Is is possible to access C members by a field of foo?
EDIT: I forgot to mention that it should be without any additional memory or significant performance loss (like with using references - mem loss).
class C
{
public:
float t;
};
class foo
{
public:
C c;
float x; //this should access c.t
} f;
float T=f.x; //returns foo.c.t
f.x=5f;
The similar example was given by Alvaro, however it regards an access between two fields of one class:
struct vector3 {
float x, y, z;
float& operator[](int index) {
assert(index >= 0 && index < 3);
return this->*members[index];
}
float operator[](int index) const {
assert(index >= 0 && index < 3);
return this->*members[index];
}
static float vector3::* const members[3];
};
float vector3::* const vector3::members[3] = { &vector3::x, &vector3::y, &vector3::z};