How to call functions from one .cpp file in another .cpp file?

前端 未结 4 1242
迷失自我
迷失自我 2021-02-06 06:55

I tried looking this up and got mixed results using header files and such.

Basically I have multiple cpp files with all my functions I made for use with binary trees, B

4条回答
  •  星月不相逢
    2021-02-06 07:22

    Declare functions in a header

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

    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
    

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

提交回复
热议问题