在源文件中创建.cpp的源文件
#include<iostream>
#include"swap.h"
using namespace std;
void swap(int a, int b)//在源文件中写函数的定义
{
int temp = a;
a = b;
b = temp;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
}
int main () {
int a = 10;
int b = 20;
swap(a, b);
return 0;
}
在头文件中创建.h的文件
#include<iostream>
using namespace std;
void swap(int a, int b);//在头文件中写声明,或则直接写函数,在源文件中(main函数中)直接调用