Without seeing the class definitions and the implementation of your accessors, it's impossible to say for sure. But my first guess is that your accessor functions are returning a copy of the object you want, rather than a reference. For instance, if you defined the accessor functions similar to the following:

ClassB ClassA::GetObjectB()

then this might be the case. Try changing this to
ClassB& ClassA::GetObjectB().

If you use the first definition, a copy of ObjectA.ObjectB is created. ditto for the GetObjectC() call. so, when you call SetOjbectD, it's setting that value in a temporary object of type class ClassC, which is then immediately discarded.

yikes, yet another typo. Please note that in my previous post, there should be the word "class " before every class definition, i.e. class ClassD{ ---- }

Sorry about the confusion.

smidgie82, thanks for your earlier reply. I tried your suggestion and it seemed to work..! Why do you think it would return just a copy rather than a reference!!! I thought it should automatically return the reference? Or do they always just return a copy? If so.. I didnt know this :s

By default, a copy is _always_ returned. That's one way that encapsulation is guaranteed, because accessors can return copies of members, so that calling functions are prevented from accessing and modifying object internals. Except when reuse of the copy is necessary, it's typically faster to return a reference, because no data duplication takes place. And if you don't want any modification of that reference to take place, you can return a constant reference:

Depends. If you want to be able to differentiate between constant and non-constant instances of your classes, then there's a point, because you can declare one version:

ClassB& ClassA::GetObjectB();

for non-constant instances, and another:

const ClassB& ClassA:GetObjectB() const;

To return constant instances that can't be modified (and neither can their members). And by using the accessor function, you can offer a consistent interface for multiple uses, which isn't possible by just referencing public data members.

Templates For Beginners
Or
How To Encourage The Compiler To Work For You
Introduction
This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…

Introduction
This article is the first in a series of articles about the C/C++ Visual Studio Express debugger. It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints. Lastly, Part 3 focuses on th…

The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.