Ok, c’est donc mon erreur: ‘Enemy’ n’a pas été déclaré dans cette étendue. L’erreur est dans le fichier map.h, même si map.h inclut ennemis.h comme indiqué
#ifndef MAP_H_INCLUDED #define MAP_H_INCLUDED #include #include #include #include #include "enemy.h" #define MAX_TILE_TYPES 20 using namespace std; class Map{ public: Map(); void loadFile(ssortingng filename); int** tile; int** ftile; bool solid[MAX_TILE_TYPES]; int width; int height; int tileSize; vector enemies; }; #endif // MAP_H_INCLUDED
Et voici ennemi.h
#ifndef ENEMY_H_INCLUDED #define ENEMY_H_INCLUDED #include "global.h" #include "map.h" class Enemy{ public: Enemy(); Enemy(float nx, float ny, float nstate); void update(Map lv); bool rectangleIntersects(float rect1x, float rect1y, float rect1w, float rect1h, float rect2x, float rect2y, float rect2w, float rect2h); void update(); float x; float y; Vector2f velo; float speed; float maxFallSpeed; int state; int frame; int width; int height; int maxStates; int *maxFrames; int frameDelay; bool facingLeft; bool onGround; bool dead; int drawType; }; #endif // ENEMY_H_INCLUDED
Quelqu’un sait ce qui se passe et comment y remédier?
Vous devez supprimer l’une des instructions #include
pour rompre la référence circulaire. Pour autoriser la compilation du code, vous pouvez déclarer l’une des classes incluses comme une simple définition.
class Map;
dans le haut du fichier Enemy.hpp, par exemple, puis incluez l’en-tête dans le fichier cpp.
enemy.h
inclut map.h
mais, map.h
inclut enemy.h
Donc, si vous incluez enemy.h
, le traitement se déroulera comme enemy.h
:
pour résoudre ce problème, supprimez #include "map.h"
de enemy.h
et remplacez-le par une déclaration avancée, class Map;
Vous devrez également modifier la void update(const Map& lv);
– utiliser un const &
et inclure “map.h” dans enemy.cpp
Il y a une dépendance circulaire dans votre inclus: map.h
inclut d’ enemy.h
et enemy.h
inclut de map.h
Vous devez supprimer l’inclusion circulaire.