Does the C ++ source file include an approved method?

I have a large C ++ file (SS.cpp) which I decided to split into smaller files so that I can navigate through it without the need for aspirins. Therefore I created

SS_main.cpp
SS_screen.cpp
SS_disk.cpp
SS_web.cpp
SS_functions.cpp

and cut out all the functions from the source SS.cpp file for them.

And finally, I included them in the source file:

#include "SS_main.cpp"
#include "SS_screen.cpp" 
#include "SS_disk.cpp" 
#include "SS_web.cpp"
#include "SS_functions.cpp"

This situation persists for several months, and these are the problems that I had:

  • Finding the whole solution (Shift-Ctrl-F in VS) does not search the included files because they are not listed as source files.

  • I had to manually specify them to enable Subversion.

, , ? , .

+3
6

cpp . , . .

+8

, , . , MIDL. .

#including. , , , , .

- , FYI , . , . , "", "" " " "".

+9

(.cpp). , /, , .

+4

CPP. Unity Builds, .

+3

, .

(, , main.cpp). .cpp, .cpp . . :

main.cpp

#include "function.h"

int main()
{
    func1() ;
}

function.h

#if !defined FUNCTION_H
#define FUNCTION_H

extern void func1() ;

#endif

function.cpp

void func1()
{
    // do stuff
}

.cpp main.cpp ( ), . , func1(), . , , .. .

+2

- . cpp, , . :
SS_main.cpp
SS_screen.cpp
SS_disk.cpp
SS_web.cpp
SS_functions.cpp

, -, , . .

, cpp , () () .

.

You cannot use the included cpp files in this context, as this does not offer any benefits. The only time I came across cpp files included was that one of them was turned on to provide code for the debugging code, and an example to compile non-built-in versions of functions. This helps in code execution in the debugger.

+2
source

Source: https://habr.com/ru/post/1721562/


All Articles