Multiple structures containing eachother instance

For the assignment, I need to declare several structures, no problem. They are declared as:

typedef struct struct1{ struct2* object; } typedef struct struct2{ struct1* object; } // functions using both struct1 and struct2 parameters 

Of course, this will give me an error since struct2 is not declared before struct1. So I tried to declare this in advance by setting

 struct struct2; 

up. However, this requires me to call the object inside the struct1 block as

 typedef struct struct1{ struct struct2* obj; } 

The functions of this structure will be used when using the parameters struct1 * and struct2 * and will be tested as such (including the constructor). Using the struct tag, as in the example above, will give me countless errors. Does anyone know how to fix this?

+4
source share
1 answer
 typedef struct s2 struct2; typedef struct s1 { struct2* object; } struct1; struct s2 { struct1* object; }; 
+6
source

All Articles