Using multiple .cpp files in c++ program?

前端 未结 4 2100
时光说笑
时光说笑 2020-11-28 04:05

I recently moved from Java for C++ but now when I am writing my application I\'m not interested in writing everything of the code in the main function I want in main functio

4条回答
  •  星月不相逢
    2020-11-28 04:15

    In C/C++ you have header files (*.H). There you declare your functions/classes. So for example you will have to #include "second.h" to your main.cpp file.

    In second.h you just declare like this void yourFunction(); In second.cpp you implement it like

    void yourFunction() { 
       doSomethng(); 
    }
    

    Don't forget to #include "second.h" also in the beginning of second.cpp

    Hope this helps:)

提交回复
热议问题