I am trying to define two structs inside a header file that both of them contain each other as objects. More specifically:
typedef struct Dweller {
int id;
int age;
std::string name, lastname;
Room room;
float foodconsume;
float waterconsume;
};
typedef struct Room {
int id;
int WIDTH = 400;
int HEIGHT = 100;
std::vector<Dweller> dwellers;
float energyconsumed;
int property;
int floor, roomno;
};
But as you might have noticed, this is an issue because the Dweller doesn't know what Room is at that point of the code. I am using C++, and I am aware that I can make them classes, then forward declare them. But I want to know if I can achieve something like this without getting them into classes. I also want to use them seperately, so I don't want one of them getting declared inside other one.
Dwellercontains aRoom, and aRoomcontains an unlimited amount ofDwellers? There's also a little problem thatDweller dwellers[];is not valid C++. But, whatever the size of this array is, you have both classes containing each other. That's the reason for the serious RAM upgrade."typedef struct"-something: you should replace it with a better C++ textbook. You only need to do something like that in C, but not C++.