Wednesday, December 29, 2010

C++ Header files

header.h files have the function prototypes

#ifndef _SIMPLE_MATH_H_
#define _SIMPLE_MATH_H_


int myfunc1( int x , int y);
int myfunc2( int x , int y);
int myfunc3( int x , int y);
int myfunc4( int x , int y);

#endif

the correspoding header.cpp file contains the body of the functions, it is located in the header file folder

#include "simple_math.h"

int myfunc1( int x , int y) {
return x + y;

}
int myfunc2( int x , int y) {
return x - y;

}

int myfunc3( int x , int y) {
return x * y;

}
int myfunc4( int x , int y) {
return x / y;
}


and an examle of a main.cpp program calling the header files


#include iostream
#include "simple_math.h"

using namespace std;

int main() {

cout << "4+2 =" << myfunc1(4,2) < return 0;
}

No comments:

Post a Comment