1、创建 .h 头文件
2、创建 .cpp 源文件
3、在 .h 头文件中,编写函数声明
4、在 .cpp 源文件中,编写函数定义
test.h
#include <iostream>
using namespace std;
void swap_my(int a, int b);
test.cpp
#include "test.h"
void swap_my(int a, int b) {
cout << a << "----" << b << endl;
}
main.cpp
#include <iostream>
#include "test.h"
int main() {
int x = 10, y = 20;
swap_my(x, y);
return 0;
}
浙公网安备 33010602011771号