Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 2nd, 2006, 10:57 AM   #1
alphonso
Programmer
 
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3 alphonso is on a distinguished road
making a header file

How does one make a header file? It's not as simple as saving the file as a header (.h) file is it? What do I have to do to?
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein
alphonso is offline   Reply With Quote
Old Apr 2nd, 2006, 11:47 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Well... it's just like you said: you save a header file as .h, just as you save a source file as .cpp.
Polyphemus_ is offline   Reply With Quote
Old Apr 2nd, 2006, 11:51 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Just don't put source code in a header file. Investigate the function of the preprocessor (# statements).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 2nd, 2006, 1:46 PM   #4
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 242
Rep Power: 3 Seif is on a distinguished road
After you've created a header file, if you want to include it in a project do this:

 #include ".\headername.h"
Seif is offline   Reply With Quote
Old Apr 2nd, 2006, 2:17 PM   #5
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
You don't need the .\
Polyphemus_ is offline   Reply With Quote
Old Apr 2nd, 2006, 3:17 PM   #6
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
A short example:
/* header.h */
#ifndef HEADER_H
#define HEADER_H

void func1(void);

void func2(int start);

void func3(int start, int end);

#endif

/* module.cpp */
#include <iostream>
#include "header.h"

using namespace std;

void func1()
{
	int i;

	for(i = 0; i < 10; i++)
		cout << i << endl;
}

void func2(int start)
{
	int i;

	for(i = 0; i < 10; i++)
		cout << i << endl;
}

void func3(int start, int end)
{
	int i;

	for(i = start; i < end; i++)
		cout << i<< endl;
}
/* main.cpp */
#include <iostream>
#include "header.h"

using namespace std;

int main()
{
	cout << "start" << endl;
	func1();
	func2(5);
	func3(10, 20);
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 2nd, 2006, 8:07 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I live in dot slash central NY.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 3rd, 2006, 2:42 AM   #8
alphonso
Programmer
 
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3 alphonso is on a distinguished road
I see...So the functions I type in have to be of void type?
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein
alphonso is offline   Reply With Quote
Old Apr 3rd, 2006, 4:29 AM   #9
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by alphonso
I see...So the functions I type in have to be of void type?
Oh my goodness, it's an example, didn't I just say that? Just test and see if it works on other functions. (Hint: It will.)
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 5th, 2006, 6:40 AM   #10
alphonso
Programmer
 
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3 alphonso is on a distinguished road
Quote:
Originally Posted by nnxion
Oh my goodness, it's an example, didn't I just say that? Just test and see if it works on other functions. (Hint: It will.)
Ok ok, I'm just asking based on what I see. Sheesh, no need to turn into a grumpy old man or something.
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein
alphonso is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC