C++

思路:

创建.h的头文件和.cpp的源文件(不是主函数所在cpp)
头文件中写函数声明
源文件中写函数定义

注意:

这三个代码再codeblocks上不能用,编译器G++的问题?

devc++ 难道也是??

先越过这个,等下次换了Qt再来验证,

反正,

vs和Linux是可以的。


主函数:

#include<iostream>
#include "swapp.h"
using namespace std;

int main()
{
    int x=1,y=2;
    swapp(x,y);
    return 0;
}

swapp.h:

#include<iostream>
using namespace std;

void swapp(int x,int y); // 函数声明

swapp.cpp:

#include "swapp.h" //把cpp和h关联起来

void swapp(int x,int y)
{
    int t=x;
    x=y;
    y=t;
    //cout包含在另一个头文件中
    //所以需要加iostrem头文件
    cout<<"x = "<<x<<endl;
    cout<<"y = "<<y<<endl;
}
原文地址:https://www.cnblogs.com/OFSHK/p/13062206.html