1、创建后缀名为.h的头文件,例如test.h。右键头文件,新建项,下方文件命名为为.h的头文件。
2、然后在头文件里面,对函数声明。其中#include <iostream>和using namespace std;是必须要的。
#include <iostream>
using namespace std;
int add3(int b); //函数的声明
3、创建后缀名为.cpp的源文件。右键源文件,新建项,下方文件命名为为.cpp的源文件。
4、然后在源文件里面,对函数进行定义,#include"test.h"是写你前面创建头文件的文件名,与前面头文件相互联系起来。
#include"test.h"
int add3(int b) //函数的定义
{
return b;
}
5、函数的调用。在任意一个源文件里面,写上你创建的头文件名,例如#include"test.h",然后就可以调用函数了。
#include <iostream>
using namespace std;
#include"test.h"
int main()
{
int b=add3(3); //函数的调用
cout << b << endl;
return 0;
}