function

Hi . how can I declaration a function into separate file ???

foe example just call name of function in main program

in the new cpp file just declare the function

then in the main file, include the other cpp file, or if you have the declaration of the function in a header, include the header in the main file and include the header in the cpp file that the function is defined.

Example:

My main cpp file:
1
2
3
4
5
6
7
8
9
#include "header.h"

int main()
{
     int x = 0;
     function(x);

return 0;
}


My header file:
1
2
3
4
5
#ifndef _HEADER_H_
#define _HEADER_H_

int function(int x);
#endif 


My other cpp file:
1
2
3
4
5
6
7
8
#include "header.h"

int function(int x)
{
     x = 5;

return x;
}
Last edited on
thankssssss
Topic archived. No new replies allowed.