// Our new header file called myheader.h
#ifndef _MYHEADER_H // if not defined
#define _MYHEADER_H // define MyHeader
#include <stdio.h> // include our extern files
#include <iostream>
using namespace std;
// declare function 3 with an argumen
// in our header file, this function returns an integer
int myFunc_3(int number);
#endif // end if not defined, and end the header file
// Our new source file
#include "myheader.h" // include our header file
int myFunc_3(int number) // define function 3
{
return number + 2;
}
// include our new header file
// (we use "" because the file is in our program folder.)
#include "myheader.h" // include our header file
int main()
{
cout << myFunc_3(5); // display the returned value of function 3
getchar(); // wait for a key to be pressed
return 0; // return zero
}
/*
Learn to use a multiple header and source files in c/c++.
This program is almost the same program as in the Header File Tutorial.
It uses function 3, and one extra source file.
The header file can be used to gain global access to your functions.
This means that your functions can be called from different source files
as long as the header file is included.
Use this to methods to obtain more structured programming as
your programs grow larger.
*/
Download Visual C++ Source Code
I hope you found this c++ tutorial useful!
Don't forget to mention Apron Tutorials in your References!