Avatar ·

How to fix compilation errors due to circular class dependencies in C++?

Hi everyone! I'm writing a simple game in C++ and ran into a problem that I haven't been able to solve for several hours. I have two classes: `Player` and `Enemy`. The player should be able to attack the enemy, and the enemy should know about the player to chase them. I'm trying to make each class contain a pointer to the other class. Here's the simplified code: **Player.h:** ```cpp #ifndef PLAYER_H #define PLAYER_H #include "Enemy.h" class Player { public: void attack(Enemy* e); int health; }; #endif ``` **Enemy.h:** ```cpp #ifndef ENEMY_H #define ENEMY_H #include "Player.h" class Enemy { public: void chase(Player* p); int health; }; #endif ``` **Player.cpp:** ```cpp #include "Player.h" void Player::attack(Enemy* e) { e->hea