Public Group

Correct Include order

This topic is 4931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey, I have problem with my include hirarchi. For my 2d based game I"m using the irrlicht engine (irrlicht.sourceforge.net) My include hirarchi looks like this: I have a BaseEntity Class which is an interface, TankEntity and ObstacleEntity both derived from BaseEntity class and include the BaseEntity.h. Each entity holds a method called OnDraw() which can draw it self. for this purpous I use the include<irrlicht.h>. My Core class (core.h and core.cpp) is the main class which holds the main loop and game rules and etc, needs to use these Entities so thie core.h file has an #include to all the entites and then i have all this problems of errors which have no sence and do not appear when i have only one include of irrlicht in a single file program, probably because of the multipul definition of the #include<irrlicht.h> comming from all the include of all the entites. How can i orgenize my project to work properly? Is there an article about how to make a good include hirerchi ? This is what it looks like
//The BaseEntity.h
#include<irrlicht.h>
...


//The TankEntity.h
#include"BaseEntity.h" //includes irrlicht
...


//The ObstacleEntity.h
#include"BaseEntity.h" //includes irrlicht
...


//The Core.h
#include"TankEntity.h" //includes irrlicht
#include"ObstacleEntity.h" //includes irrlicht
//now irrlicht.h is included 2 times
...



Share on other sites
This problem should never appear. A well-written .h file will contain something like the following
//bleh.h#ifndef _BLEH_H#define _BLEH_H//include file contents goes here#endif //_BLEH_H

which will prevent the file from being included twice

Share on other sites
Article on include files (and some other things about organizing code).

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 10
• 11
• 9
• 9
• Forum Statistics

• Total Topics
634146
• Total Posts
3015782
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!