Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

tcs

Those includes make me mad!

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

Hi! I have a serious problem while developing my 3D engine. I diveded it into logical parts. I have a loader class that passes all faces to the HSR (BSP, Portals - such stuff) class, This class has to interact with my Renderer class, all those classes need acess to my triangle class and so on. So I have to put includes for every class into every other class. This causes a million compiler errors. (I''m usinbg the VC++ generated inclusion guards). I tried to create a global engine.h where everything is included to avoid this problem. I tired everything. With inclusion guards, include the stuff in a different order, use more incl guards.... Sometimes it works, but if I include a new class, or change something, everything is broken again. There must be a easy way to do such recursive includes, what do you guys do ??? Help ! TIm

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
#ifndef _myheaderfile_h_
#define _myheaderfile_h_

#include "includes3d.h"

try doing this, it sometimes helps.

#endif


try making an INCLUDES3D.H file in which all header files for the related subsystem are included.

eg:

#ifndef _includes3d_h_
#define _includes3d_h_

#include "myvertex.h"
#include
#include "myotherstuff.h"

#endif

It might help. I usually find keeping everything organised is a problem. At least you''re off to a good start seperating everything into subsystems, so you''re heading in the right direction.

Share this post


Link to post
Share on other sites
The problem is that include files are being included more than once. You can figure out the rest. Make a MFC applicaiton useing appwizard and see how they safegaurd their header files againt this.

Share this post


Link to post
Share on other sites
Hey ! I''m not such a idiot... ;-))
I have of course inclusion guards (I said that).

And I have a big include file (I said that, too).

But the problem is strange. It''s hard to describe. If you include aaa.h, bbb.h and ccc.h into a global.h and then include your global.h into aaa.h, bbb.h and ccc.h you get really strange problems !

I really don''t understand this, and I think it is a major problem of C++, such stupid issues shouldn''t be there in such a language !!!

Share this post


Link to post
Share on other sites
I get various erros, depending on the order in which my includes are sorted in my global.h. I figured out it works better when I put the #include global.h outside the inclusion guards of my class headers...

I tried everything. I think the problem is that I include file b in file a, and then include file a in file b.

Damn, I can''t do anything with my engine until this problem is solved.

Share this post


Link to post
Share on other sites
Actually, the issues aren''t themselves in the language, just in how you use it

Why are you including a in b, then b in a?
If it''s because you need the classes, try forward declaration. Example:

B.h

class A;

class B
{
// ...
};


A.h:

class B;

class A
{
// ...
};



Im pretty sure that''s how it works...

Hope this helps!

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge

Share this post


Link to post
Share on other sites
Yes, you''re right. But I think that this is just pain for the coder that could be avoided if the language would be well-designed...

Why I need to include A into B:

My OBJ Loader loads a file from disk and creates a 3DMesh object from it. But my 3DMesh object needs some structures etc. from the OBJ loader.

I can''t put the includes under the class declaration. I have member variables and functions that need the other class to be declared !

So I can''t use your approach...

And my triangle class is included in all my classes, and some of my classes are included in my triangle class.

I doesn''t work.....

Share this post


Link to post
Share on other sites
Yes, you''re right. But I think that this is just pain for the coder that could be avoided if the language would be well-designed...

Why I need to include A into B:

My OBJ Loader loads a file from disk and creates a 3DMesh object from it. But my 3DMesh object needs some structures etc. from the OBJ loader.

I can''t put the includes under the class declaration. I have member variables and functions that need the other class to be declared !

So I can''t use your approach...

And my triangle class is included in all my classes, and some of my classes are included in my triangle class.

It doesn''t work.....

Share this post


Link to post
Share on other sites
Hey doesn''t anyone have an idea about this ? Is C++ really not able to handel just a few simple include statements ?
Does no one have classes that rely on each other ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Qoy has the right idea. To expound on that idea...

The simple way to avoid circular includes (when xxx.h includes yyy.h and yyy.h includes xxx.h) is to never include any header you create in another header. Including system headers is ok because you can be sure they won''t include any of your code, thus avoiding a circular include. Instead, if I need to use class XXX in yyy.h (and this is exactly what Qoy wrote) do the following:

class XXX;

class YYY {
...
XXX *X;
...
};

this tells the compiler that XXX is a valid symbol and that it is defined elsewhere. I think the XXX is resolved in the compiler''s second pass (at that point it will have a record of the external definition of XXX).

Share this post


Link to post
Share on other sites

  • 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!