Inclusion croisée problématique
Bonjour (bonsoir ou bonne nuit :mrgreen:) à tous
J'ai un projet dont les fichiers header et le main suivent le shéma suivant
main.cpp : inclue : engine.h
engine.h : inclue : item.h, global.h
item.h : inclue : graphicitem.h, global.h
graphicitem.h : inclue : global.h
global.h : inclue : engine.h
La seule chose importante à savoir sur les classes contenues est que item hérite de graphicitem.
J'ai reussi à avoir le probleme avec le code suivant :
main.cpp
Code:
1 2 3 4 5 6
| #include <engine.h>
#include <global.h>
int main()
{
} |
engine.h
Code:
1 2 3 4 5 6 7 8 9 10 11
| #ifndef ENGINE_H
#define ENGINE_H
class Engine;
#include <global.h>
#include <item.h>
class Engine {};
#endif |
item.h
Code:
1 2 3 4 5 6 7 8 9 10 11
| #ifndef ITEM_H
#define ITEM_H
class Item;
#include <global.h>
#include <graphicitem.h>
class Item : public GraphicItem {};
#endif |
graphicitem.h
Code:
1 2 3 4 5 6 7 8 9 10
| #ifndef GRAPHICITEM_H
#define GRAPHICITEM_H
class GraphicItem;
#include <global.h>
class GraphicItem {};
#endif |
global.h
Code:
1 2 3 4 5 6
| #ifndef GLOBAL_H
#define GLOBAL_H
#include <engine.h>
#endif |
et enfin les fichier engine.cpp, item.cpp, graphicitem.cpp et global.cpp ne contenant que la directive #include avec le nom du header correspondant.
Le préprocesseur m'affiche le message suivant
Code:
1 2 3 4 5 6 7
|
In file included from ./engine.h:7,
from ./global.h:4,
from graphicitem.h:6,
from graphicitem.cpp:1:
./item.h:9: error: invalid use of incomplete type 'struct GraphicItem'
graphicitem.h:4: error: forward declaration of 'struct GraphicItem' |
Je sais plus trop où ni quoi chercher après de nombreuses tentatives vaines sur le net.
Merci d'avance. :D