且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从另一个.cpp文件中的一个.cpp文件调用函数?

更新时间:2023-01-07 08:58:53

在标头中声明函数

//MyFunctions.h
int myFunction1(int,int);
int myFunction2(int,int);


在MyFunctions.cpp中实现它们


Implement them in MyFunctions.cpp

//MyFunctions.cpp
#include "MyFunctions.h"
int myFunction1(int a, int b){
    //your code
}
int myFunction2(int a, int b){
    //your code
}


将标题包含在所需的任何文件中


Include the header in whatever file you want

//OtherFile.cpp
#include "MyFunctions.h"
//Now you have access to the functions defined in MyFunctions.h in this file


我不知道miniGW,但是它看起来应该像g ++ otherfile.cpp MyFunctions.cpp ...


I dont know miniGW but it should look something like g++ otherfile.cpp MyFunctions.cpp ...