Question About Header Files

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
DoubleImpact
Posts: 4
Joined: July 3rd, 2012, 11:09 am

Question About Header Files

Post by DoubleImpact » July 3rd, 2012, 11:17 am

Why do we need them at all? What's stopping us from taking all of the stuff that's written there and putting it in the .cpp file?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Question About Header Files

Post by chili » July 3rd, 2012, 12:43 pm

Usually the stuff in the header file is needed in more than one .cpp file. For example, D3DGraphics.h is needed in D3DGraphics.cpp and in Game.cpp, Game.h is needed in Game.cpp and Windows.cpp, etc.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Question About Header Files

Post by Asimov » July 4th, 2012, 2:59 pm

Hi DoubleImpact,

When I wrote my last game I put the header and the whole class in the header file. It works quite well, but after watching Chilli's tutorials it makes sense to keep them separate, and then when you include the header file in another class you are only including the header information and not the whole class.

I have read a few C++ books, but not all of them tell you to keep your header files separate, so it can be misleading.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
npissoawsome
Posts: 114
Joined: June 8th, 2012, 3:01 pm

Re: Question About Header Files

Post by npissoawsome » July 4th, 2012, 7:16 pm

DoubleImpact wrote:Why do we need them at all? What's stopping us from taking all of the stuff that's written there and putting it in the .cpp file?
Honestly, I think coding C++ without headers would be a mess, full of prototyping and ugh...

Post Reply