What's the difference

Header files and cpp files

Page 1 of 1

3 Replies - 601 Views - Last Post: 04 May 2010 - 10:42 AM Rate Topic: -----

#1 ZOMBIE!!!  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 206
  • Joined: 28-October 09

What's the difference

Posted 03 May 2010 - 11:00 AM

I know that there are a few differences with using multiple .cpp files and using headers:

. You have to prototype functions with .cpp files
. You have to use #include for header files


Other than that what are the pros and cons for both?
Is This A Good Question/Topic? 0
  • +

Replies To: What's the difference

#2 joesyuh  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 175
  • Joined: 30-September 08

Re: What's the difference

Posted 03 May 2010 - 11:20 AM

I am confused. Are you asking what the difference is in using .h files and .cpp files? From my understanding when you are using multiple .cpp files you "need" a .h file.
Was This Post Helpful? 0
  • +
  • -

#3 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: What's the difference

Posted 03 May 2010 - 12:23 PM

Header files are just a convention. You technically don't need them.

You already know about .cpp files. Source files. That's where source code is. Here's the thing: source files are compiled independently. So we use declarations to indicate types, functions, etc. present in other source files. But it's a complete pain to keep typing out each declaration manually, and if we ever need to change anything, we have to go through all the source files, fixing all declarations.

It would be awfully convenient if we could just dump all the declarations in one file, and then have the computer copy paste the contents to every source file as we instruct it to. That's precisely what a header file is.
Was This Post Helpful? 1
  • +
  • -

#4 ZOMBIE!!!  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 206
  • Joined: 28-October 09

Re: What's the difference

Posted 04 May 2010 - 10:42 AM

View PostOler1s, on 03 May 2010 - 11:23 AM, said:

Header files are just a convention. You technically don't need them.

You already know about .cpp files. Source files. That's where source code is. Here's the thing: source files are compiled independently. So we use declarations to indicate types, functions, etc. present in other source files. But it's a complete pain to keep typing out each declaration manually, and if we ever need to change anything, we have to go through all the source files, fixing all declarations.

It would be awfully convenient if we could just dump all the declarations in one file, and then have the computer copy paste the contents to every source file as we instruct it to. That's precisely what a header file is.


Thanks that helped clear it up a bit. I had some stuff mixed up. +1 Rep for you.

This post has been edited by ZOMBIE!!!: 04 May 2010 - 10:46 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1