LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2012, 04:05 PM   #1
michaelinux
Member
 
Registered: Apr 2009
Location: El Salvador
Distribution: Slackware -current
Posts: 166

Rep: Reputation: 17
for c++ programmers, header files?


for all c++ programmer out there, i am trying to learn c++ and since i know some java and c#, it hasn't that difficult (yet). One thing that i really don't get yet is the use of header files, i mean having to write a .h file with the definitions and make sure all the right headers are included and then the .cpp file for the implementation, i find that a long process compared to java or c# where you just start writing your classes and functions and that's it.
i remember reading that some programmers don't use .h files anymore and that it could be ignored. I guess this is because they were talking about personal projects but idk.
so what is the main use of header files and why would i bother in writing one everytime i need a new class.
sorry if it's a really noob question.
 
Old 01-17-2012, 05:01 PM   #2
keirey
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Rep: Reputation: 2
Header files are used to separate the interface (function declarations and public data types) from implementation (how the functions are constructed and how private data types are used). This makes it possible to "hide" the implementation from the end user.
Suppose you have a working program and you find a better algorithm or way to implement a function. You could then change the implementation of the function in the .cpp file, as long as the function parameters remain the same. Then you can simply recompile the program using the new .cpp file. That way there is no need to change the header and main files.
For simple programs and exercises, it is not always necessary to have separate header files, however, for larger programs with many classes or programs with classes to be used by other end users, I find it a good habit to use separate header and definition files.

For a more extended discussion check out:
http://en.wikipedia.org/wiki/Header_file

You should also read "Thinking in C++, Vol.1" by Bruce Eckel, which you can download from several sources online.

Hope this helps.

Last edited by keirey; 01-18-2012 at 02:24 PM.
 
  


Reply

Tags
c++, linux, programing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux header files missing and v4l files unable to compile szutshi Linux - Newbie 5 09-13-2011 02:00 PM
using header files: how do you ref and put fumulas in headers files cuthbertmd1 Programming 7 02-15-2011 06:25 AM
How to check missing header files included from another header file adisan82 Linux - Software 1 01-28-2011 03:57 AM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration