Jump to content
  • Advertisement
Sign in to follow this  
King_DuckZ

Headers including other headers

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

Hello everyone, I've been having this problem for quite a while, and I'd like to hear what other people think about it. It often happens, when declaring a class, that it uses a pointer or a reference to some class, struct or union declared somewhere else. Using predeclaration most of the times does the trick, but sometimes it's not enough. An example: I'm writing an input management class, using SDL. I need to store a private pointer to the SDL_Joystick struct, which is actually a typedef to _SDL_Joystick. Predeclaring the typedef won't work, and I don't want to predeclare _SDL_Joystick, so I'm forced to include the whole SDL.h whithin my .h file. The same happens with stl stuff. Leaving alone compiling time, and assuming that there is a precompiled header already including SDL.h first so that this second inclusion is getting "pragmaonced" out, is there any good reason for which I shouldn't include potentially big headers in my headers, or am I just being maniacal?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by King_DuckZ
An example: I'm writing an input management class, using SDL. I need to store a private pointer to the SDL_Joystick struct, which is actually a typedef to _SDL_Joystick. Predeclaring the typedef won't work, and I don't want to predeclare _SDL_Joystick, so I'm forced to include the whole SDL.h whithin my .h file. The same happens with stl stuff.


Did you try:

struct _SDL_Joystick;
typedef _SDL_Joystick SDL_Joystick;

?

Quote:
Original post by King_DuckZ
Leaving alone compiling time, and assuming that there is a precompiled header already including SDL.h first so that this second inclusion is getting "pragmaonced" out, is there any good reason for which I shouldn't include potentially big headers in my headers, or am I just being maniacal?


You should probably try the Pimpl idiom.

Share this post


Link to post
Share on other sites
Nope, I will try right now, I think it's a better idea than including the whole header anyways. Thank you for the link, I didn't know there were official "best practices" to follow, and I found it very interesting!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!