Jump to content
  • Advertisement
Sign in to follow this  
dagabe14

Includes issues

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

I'm making a game that has several projects in it, all except one being libraries (like Graphics or AI), the remaining one being the actual game. I am currently re-structuring all the projects since I was using pre-compiled headers wrong. My plan is to have 3 main files for each library: pre-compiled, core, and include. Core would have all the enums, #defines, and consts for that library. Include would have all the .h, so that if another library needs this library, all it has to do is include this file. This file will include the core file. Pre-compiled would have all the c/c++/stl/other libraries needed, like windows.h or <vector>, and math library. This file will include the core file. The main thing about this design is that I want the include file to be as clean as possible, not including anything included in the pre-compiled, that way if another library includes this file, then it wouldn't get all the extra garbage (for lack of better word). The main issue that i have is that some classes require vector or types from the math library as member variables, but its not defined in the .h two fixes that i see are: 1) Include the pre-compiled in the .h, which means that the pre-compiled will be the include, which then will be on all the libraries, killing my compile time. 2) Include the library in the .h, defeating the purpose of having it in the pre-compiled. Another possible fix is forward declarations, but how do i forward declare a std::vector? this seems too complicated, and more of a hack than anything. Is there a better solution to my design issue that anyone can help me with?

Share this post


Link to post
Share on other sites
Advertisement
Maybe im wrong but...

if you want to forward declare the vector you could simply make it a pointer?

.h---------------
class vector; //forward declare
vector *myVec; //temp defined pointer
-----------------

.cpp-init()------
myVec = new std::vector<type>;
-----------------

never done this before btw. But I personally would just include a utility header that only contains those types of pre compiled classes.

Share this post


Link to post
Share on other sites
I don't believe you can forward declare standard C++ library types because if memory serves it is illegal to open namespace std in your code.

Share this post


Link to post
Share on other sites
well, i wasn't really trying to forward declare that, i was just saying that is a possibility, but unless i use void pointers, and the cast that to the proper stl class (which is still too much of a problem) then forward declarations will not really help.

the way that i figured i fix my design issue is to allow only the necessary includes in the header file, it won't be as clean as I wanted, but it will be clean enough.

Share this post


Link to post
Share on other sites
I think it's ok to include the math library in the .h file. What will happen is that it won't effect your project at all because the pre-compiled header is the first thing that's included in each cpp file. So when another .h file goes to include something that was in the precompiled header it will hit the #ifndef block at the top of the library header file, see that it is already defined (from the precompiled header) and just skip over the rest.

Share this post


Link to post
Share on other sites
If your classes use vectors as member variables, then the definition of vector needs to be visible whenever your classes are defined. There's no way around that. Otherwise the compiler won't know how large your objects are, or where their members are.

Have you verified how much longer the build takes when <vector> is included? Are you sure its internals aren't being included already (STL headers are very interdependent on most implementations)?

If you're determined to have your headers without their headers, the only solution is the pImpl idiom, which is far more trouble than it's worth.

Share this post


Link to post
Share on other sites
Quote:

If your classes use vectors as member variables, then the definition of vector needs to be visible whenever your classes are defined. There's no way around that. Otherwise the compiler won't know how large your objects are, or where their members are.


Well, after long considerations, and talking to multiple people, i arrived to this same conclusion. The main thing that I am now working on is avoiding including header files where they are not absolutely needed, that way that Include file that I mentioned is as "clean" as possible.

Quote:

Have you verified how much longer the build takes when <vector> is included? Are you sure its internals aren't being included already (STL headers are very interdependent on most implementations)?


I am unsure if it takes longer, I'm hoping that its a negligible effect on my compile time.

Quote:

If you're determined to have your headers without their headers, the only solution is the pImpl idiom, which is far more trouble than it's worth.


it doesn't sound that complicated, but I see your point.

Thanks for the input!

Share this post


Link to post
Share on other sites
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!