![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Well... it's just like you said: you save a header file as .h, just as you save a source file as .cpp.
|
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 242
Rep Power: 3
![]() |
After you've created a header file, if you want to include it in a project do this:
#include ".\headername.h" |
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
You don't need the .\
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#10 | |
|
Programmer
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3
![]() |
Quote:
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|