I have two classes A and B, which are defined as follows:
class A
{
public:
void *connector;
};
class B
{
public:
void *connector1;
void *connector2;
};
First, suppose I create three objects C1, C2, and C3 based on these classes,
A C1;
B C2;
A C3;
And I use the following code to connect them
C1.connector = &C2;
C2.connector1 = &C1;
C2.connector2 = &C3;
C3.connector = &C2;
So, at the moment I have this: C1 ↔ C2 ↔ C3 (first example).
Important: the reason I use void pointers in all classes is because I cannot predict from the very beginning how the objects will connect. For example, the answer to this question should be valid if I create the fourth object and make these connections (C1 and C2 the same as before):
B C3;
A C4;
C1.connector = &C2;
C2.connector1 = &C1;
C2.connector2 = &C3;
C3.connector1 = &C2;
C3.connector2 = &C4;
C4.connector = &C3;
which corresponds to this C1 ↔ C2 ↔ C3 ↔ C4 (second example).
. , , , , . , , . , , C2 C1 .
1) , , . , ( , ).
2) , , , , .
. , , , , B , , .
, ,
int get_value();
A, B ( ). , C2 C1, C3 C2. , C2 C3 .
, , , . , , C2 C1, C3 C2 (. 2 ).
, , , C2/C3 get_value C1/C2, C2/C3 / , .
, , , , , , . , , - , - .
.