Those includes make me mad!
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
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
April 30, 2000 12:28 PM
#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.
#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.
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.
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 !!!
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 !!!
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
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.
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.
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
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
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
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.....
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.....
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
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.....
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.....
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
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 ?
Does no one have classes that rely on each other ?
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
April 30, 2000 04:32 PM
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement