How to write a header file

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 5
Reputation: Saleh is an unknown quantity at this point 
Solved Threads: 0
Saleh Saleh is offline Offline
Newbie Poster

How to write a header file

 
2
  #1
May 25th, 2004
where can i find out a detailed information about How to write a header file ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: How to write a header file

 
2
  #2
May 25th, 2004
A header file is made up of pre-processor directives, classes, namespaces etc. a good place to look at is cplusplus.com. look at the classes, objects and namespaces chapters...
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: How to write a header file

 
1
  #3
May 27th, 2004
My God I even had a comp science teacher ask me this.Arrrg one will go mad.

It's simple.Cut a few funtions out of you code and paste them in a file with a .h extension and call #include "your_header_name.h" to include that.

Note: not < > but " " if it's in the current directory else you have to supply the full or relative path.

All the rules are same as normal C++ syntax.

----------------------------------------------
That was very simple thing.Headers can be used for more things.They can just contain funtions declarations without definitions.In that case it will be used to link to a static library.

Eg.Make a header file with 2 funtion declarations like fun1(); fun2(); only
Include it with a cpp file and call the funtions and compile.

You will get no errors on compile but on linking you will see an error similar to the following:

undefined module fun1() refferenced from Module main.cpp
undefined module fun2() refferenced from Module main.cpp

I hope you understand a header in not really diffrent from a cpp file.Btw you can also include .cpp files.

Eg: #include "wow.cpp"
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: How to write a header file

 
1
  #4
Jun 17th, 2004
It is very very simple:


write some functions||define some macros||define structures/classes etc...
DO NOT include a main() function
save it with the name you want
e.g header.txt/cpp/in/out/...
you use it through: #include "..."
if you have variables in your header, do not redeclare them in your programs or it will give you an error "Multiple declaration for variable..."
:p
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: How to write a header file

 
0
  #5
Jun 18th, 2004
Even if you include main() in a header and dont declare main() in any other funtion the program will complie and work properly.Headers are just a way to organise code.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: How to write a header file

 
0
  #6
Jun 18th, 2004
well if you include main() in a header that would be more like a program than like a header but anyway you can
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 26084 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC