Jump to content
  • Advertisement
Sign in to follow this  
spree

Correct Include order

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!