Jump to content
  • Advertisement
Sign in to follow this  

Keeping track of #includes?

This topic is 2788 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

So I've started writing my own project in C++. I was getting along quite well I thought, until I started to get compile errors with multiples of the same header files trying to be compiled. I took a closer look at my #include statements and came to a terrifying realization that it was a mess. A HUGE mess. I was amazed it had taken me that long to run into that error.

My question is; how do you keep track of your includes? What method works best? (eg. flow chart, string and bulletin board, white board, just a plain list....)

Also, what is the best way to create the hierarchy of includes, for example:

Lets say I have these files.
Bone, Mesh, Model, Entity, Manager, Updater, Main

Model relies on Mesh and Bone
Entity relies on Model
Manager relies on Mesh
Updater relies on Entity
Main relies on Manager, Updater.

What is the best way to include these files according to their individual dependencies?

I get stuck like this:
#include "Bone"
#include "Mesh"

#include "Model"

#include "Mesh"

#include "Entity"

What now? What do I include in Main? I need both Updater and Manager, but if I include both, I've included Mesh twice!?

I've got no strategy to contend with this. Any suggestions?

Share this post

Link to post
Share on other sites
Have you tried something like include guards?

Share this post

Link to post
Share on other sites
Also, forward declarations can help you remove #include directives that aren't needed.
e.g.// #include "render/mesh.h" //instead of this, use a:
class Mesh; // forward declaration - says "class Mesh exists, but I don't know what it is, yet"
class Model
Mesh* m_mesh;

Share this post

Link to post
Share on other sites
Make sure your headers have fallowing defines:

#ifndef _HEADER_NAME_
#define _HEADER_NAME_



this will make sure that the content of the header is processed only once

Share this post

Link to post
Sign in to follow this  

  • Advertisement

Important Information

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

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!