Code:
//in B.h
class A;
class B{
A *ContainingObject;
....
B();
void SetContaingObject(A *a);
void ShowContaingObject();
};
//in B.cpp
....
void B::SetContaingObject(A *a)
{
if(a!=NULL)
ContainingObject=a;
}
B::B(){
ContaingObject=NULL;//#define NULL 0x0
}
//in A.h
class A{
...
B obj;
};
//in A.cpp
A::A(){
obj.SetContainigObject(this);
........
}
So the object ot type B, which is in the object of type A (obj) can perform operation on the containing object:
Code:
//in B.cpp
void B::ShowContaingObject()
{
if(ContaingObject)
cout<<(void*) ContaingObject;
}
I have created the example in the editor of replies, so it may contain syntax errors, but I think the may idea is clear.
Wish me luck- Tomorrow I have a test on Complex Analisis.