Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Keeping track of #includes?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Labrasones   Members   -  Reputation: 339

Like
0Likes
Like

Posted 27 February 2012 - 07:20 PM

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?

Sponsor:

#2 bd36   Members   -  Reputation: 118

Like
0Likes
Like

Posted 27 February 2012 - 08:20 PM

Have you tried something like include guards?
http://www.cplusplus.com/forum/articles/10627/
http://www.learncpp.com/cpp-tutorial/19-header-files/

#3 fastcall22   Crossbones+   -  Reputation: 4476

Like
0Likes
Like

Posted 27 February 2012 - 08:23 PM

There is also Organizing code files in C and C++.
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#4 Hodgman   Moderators   -  Reputation: 31939

Like
1Likes
Like

Posted 27 February 2012 - 09:58 PM

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;
};


#5 Labrasones   Members   -  Reputation: 339

Like
0Likes
Like

Posted 28 February 2012 - 03:50 PM

Thanks for the suggestions! I think Hodgman's suggestion is exactly what I was looking for.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS