"markww" <ma****@gmail.comschrieb im Newsbeitrag
news:11*********************@p79g2000cwp.googlegro ups.com...
Hi,
I have a two classes setup like this:
class CChild {
void Something();
};
class CParent {
string m_strData;
CChild m_Child;
};
Is there anyway that the cchild class member can get at m_strData in
the parent like:
void CChild::Something()
{
GetParentClass()->m_strData;
}
An instance of the CParent class can pass a pointer to itself to m_Child,
for example in its constructor. The child saves this pointer and can use it
to access its parent. If the child can exist longer than its parent (not if
the child is a member of its parent class), the parent should notify all its
children that is it about to be destroyed. That would best be done in the
parent's destructor.
And of cause, the client class can only access public members of the parent
class (unless it is a friend).
HTH
Heinz