[Solved] Header files

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

[Solved] Header files

Post by zodiac976 »

This is probably a stupid question but how can I link
multiple header files using just 1 header file include
in my projects instead of including each and every
one seperately?

mainHead1.h, mainHead2.h, mainHead3.h

#include "mainHead1.h" //I want to be able to include head2 and head3 with it.

int main()
{
return 0;
}
Last edited by zodiac976 on Sun Jun 28, 2009 5:46 pm, edited 1 time in total.
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: Header files

Post by zodiac976 »

Never mind I figured it out by just storing all includes
in a header file then use that header file to link all
other header files.
Protimus
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 25
Joined: Mon Jun 01, 2009 9:27 pm
Current Project: Game Engine
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Jackson, AL
Contact:

Re: Header files

Post by Protimus »

[Solved]?
Judge not a man by his language but by his use of the language.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: [Solved] Header files

Post by MarauderIIC »

I think you would be better of #include-ing every one individually, that way your files are guaranteed to only link to what they need. If you need an include in an include (like you're using strings in your class definition), then you need to #include <string> using namespace std; inside that header. But still, you want to keep includes in every file to the minimum required.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: [Solved] Header files

Post by dandymcgee »

MarauderIIC wrote:I think you would be better of #include-ing every one individually, that way your files are guaranteed to only link to what they need. If you need an include in an include (like you're using strings in your class definition), then you need to #include <string> using namespace std; inside that header. But still, you want to keep includes in every file to the minimum required.
Just as a side note: The last big project I was working on, I ended up somehow creating a circular dependency of header files (~5 different classes depended on each other). You'll want to avoid that at all costs as it can cause some pretty bad headaches. ;)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: [Solved] Header files

Post by zodiac976 »

So I am better off using the header files seperately?
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: [Solved] Header files

Post by dandymcgee »

zodiac976 wrote:So I am better off using the header files seperately?
Yes, include them one per line only where you need them.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply