class Object3
{
int obj3Data;
};
class Object2
{
Object3 obj3;
};
class Object1
{
Object2 obj2;
int dataFromOtherObj;
};
Object1 anObj;
anObj.dataFromOtherObj = anObj.obj2.obj3.obj3Data;
Obviously this is an unrealistic class design and is from an external point-of-view (you'd want to put the assignment code in class member functions).
class Object3
{
public:
int Data() const { return obj3Data; }
private:
int obj3Data;
};
class Object2
{
Object3 obj3;
};
class Object1
{
Object2 obj2;
int dataFromOtherObj;
};
Object1 anObj;
anObj.dataFromOtherObj = anObj.obj2.obj3.Data();
In this case Object3::Data() is an access function, or a 'getter'.
Edit: Note that the above won't compile as such, as the default permission is private, so all the other members are private, too. You'd need to add a public: to each.
Jim