c++で他のファイルから関数を呼び出す方法

以下の記事を参考にする。

c++ - How to call functions from one .cpp file in another .cpp file? - Stack Overflow

 

まずは関数を含むコード書く。

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

次にヘッダファイルを書く。

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

最後にmainのファイルに以下のように書く。

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

こうすることで例えば

myFunction1(5,5);

のように関数を利用出来るようになる。