Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

communication between two classes at the same level

2 views
Skip to first unread message

Michel Bardiaux

unread,
May 13, 2003, 7:35:48 AM5/13/03
to

Luis Alberto wrote:
> My question is about communication between two classes.
> Suppose you have objects from class A that need to be able to
> communicate with objects from
> class B but also objects from class B need to communicate with objects
> of class A. If I include class B
> in class A then I can not include class A in class B.

Let's apply some logic here. If A can talk to B abd B can talk to A,
then they necessarily share a 'common tongue'. Hence, A *and* B both
inherit from the class implementing that commonality, let's call it T
(better not to call it C!). In C++, T would use pure virtual functions.
An OO implementation in C would have function pointers in the 'struct'
T, which would be filled by the 'constructor' for A or B.

> I have found one
> solution but I'm asking you guys,
> to see if you have a better solution. In class A and in class B,
> I'm declaring pointers of type "void" that will be the pointers to
> objects from class B or class A,
> so no need to write include directives in my header files; and in my
> source files I write the include directives and then
> every time I reference the void pointers, I cast them to either class
> A or class B depending in which class I'm using them.
> In that way I don't have linker problems, but I was wondering if there
> is a better and more elegant solution or
> it is just C++ that does not allow communication of objects in the
> same level.


--
Michel Bardiaux
Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
Tel : +32 2 790.29.41

Eric Sosman

unread,
May 13, 2003, 11:30:19 AM5/13/03
to
Michel Bardiaux wrote:
>
> Luis Alberto wrote:
> > My question is about communication between two classes.
> > Suppose you have objects from class A that need to be able to
> > communicate with objects from
> > class B but also objects from class B need to communicate with objects
> > of class A. If I include class B
> > in class A then I can not include class A in class B.
>
> Let's apply some logic here. If A can talk to B abd B can talk to A,
> then they necessarily share a 'common tongue'. Hence, A *and* B both
> inherit from the class implementing that commonality, let's call it T
> (better not to call it C!). In C++, T would use pure virtual functions.
> An OO implementation in C would have function pointers in the 'struct'
> T, which would be filled by the 'constructor' for A or B.

All very interesting, I'm sure -- but more interesting
to the inhabitants of comp.lang.c++ than to those of us
still in the backwaters of comp.lang.c. Followups set.

--
Eric....@sun.com

0 new messages