たとえば、Player、Bot、Game の 3 つのクラスを持つ小さな Computergame があります。
プレーヤーには、プレーヤーがボットと衝突するかどうかをチェックするメソッドがあります
// Player.h
#include Game.h
#include Bot.h
class Player {
private:
bool collision(Game g) {
for (Bot bot: g.bots)
...
}
};
Bot.h (シンプルに保たれていますが、実際の位置やこれまでのようないくつかの他の属性があります)
// Bot.h
class Bot {
public:
Bot()
};
ゲームクラスは、ゲームループとボットのリストを処理します
//Game.h
#include Bot.h
#include Player.h
class Game {
public:
Player player:
std::vector<Bot> bots
void loop() { player.collision() }
};
ここで、Game.h に Player.h が含まれているという問題があり、その逆もあります。
どうすればこれを解決できますか?