As the title says, can it be done?
struct Room{
char *type; //Lecture hall, laboratory, etc.
char *name;
int *capacity; //How may people it can hold
struct Building *building;
};
struct Building{
char *name;
char *type; //Administrative, school, etc.
int *rooms; //How many does it have
int *total_capacity; //Total capacity of the rooms
struct Room *room;
};
I'm trying to kind of simulate a database using struct
arrays to simulate tables.
As it can be seen above, I have a "table" of buildings and another one for rooms. Each building has a list of pointers to its rooms, and each room needs a pointer to the building that it is situated in.
And here comes the problem, whichever is defined first will complain that the other is not defined, which, for functions, could easily be solved with using a prototype, but I can't find anything of the sort for struct
I tried things like
struct Building;
struct Building();
struct Building{};
struct Building(){};
Along with the typedef
variation but nothing seems to work. Is there such a thing as prototyping for structs? If not, what is the workaround, if any?
struct Building; struct Room;
. Subsequently you can declare pointers to either struct as needed. Typedefs will neither help nor hurt; it's the forward declarations that will help.