Headers including other headers

Started by
2 comments, last by SiS-Shadowman 14 years, 10 months ago
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?
[ King_DuckZ out-- ]
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.
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!
[ King_DuckZ out-- ]
When I use code that doesn't change, I include it in my header and the precompiled header which does the job.

This topic is closed to new replies.

Advertisement