Public Group

# 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.

## 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:
Model:
#include "Bone"
#include "Mesh"

Entity:
#include "Model"

Manager:
#include "Mesh"

Updater:
#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 on other sites
Have you tried something like include guards?
http://www.cplusplus.com/forum/articles/10627/

##### 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 { private: Mesh* m_mesh; };

##### Share on other sites
Thanks for the suggestions! I think Hodgman's suggestion is exactly what I was looking for.

##### Share on other sites
Hidden
Make sure your headers have fallowing defines:

code

#endif

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

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 43
• 75