I am writing a Roguelike game and am having trouble with the header files Monster.h and player.h. Both rely on the other so I am using forwards declaration. However Monster.h is getting an error with the forward declaration and the function using player. here is the forwards declaration of each:
1 2 3 4 5 6 7 8 9 10 11
//Monster.h...
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <string>
#include "Player.h"
class Player;
class Monster
{
private:
//...
1 2 3 4 5 6 7 8 9 10 11
//player.h...
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <string>
#include "Monster.h"
class Monster;
class Player
{
private:
//...
And heres the function in Monster.h that is causing problems:
1>------ Build started: Project: Simple Rogue, Configuration: Debug Win32 ------
1> Simple Rogue.cpp
1>c:\users\gio\desktop\documents\c++ programs\2d & 3d games\simple rogue\roguelike game\monster.h(64): error C2027: use of undefined type 'Player'
1> c:\users\gio\desktop\documents\c++ programs\2d & 3d games\simple rogue\roguelike game\monster.h(9) : see declaration of 'Player'
1>c:\users\gio\desktop\documents\c++ programs\2d & 3d games\simple rogue\roguelike game\monster.h(64): error C2228: left of '.damage' must have class/struct/union
1> Levels.cpp
1>c:\users\gio\desktop\documents\c++ programs\2d & 3d games\simple rogue\roguelike game\monster.h(64): error C2027: use of undefined type 'Player'
1> c:\users\gio\desktop\documents\c++ programs\2d & 3d games\simple rogue\roguelike game\monster.h(9) : see declaration of 'Player'
1>c:\users\gio\desktop\documents\c++ programs\2d & 3d games\simple rogue\roguelike game\monster.h(64): error C2228: left of '.damage' must have class/struct/union
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How do I fix this?
Thanks in advance for any help!