Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is including C++ source files an approved method?

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

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

and cut-pasted all the functions from the initial SS.cpp file to them.

And finally I included them in the original file :

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

This situation remains for some months now , and these are the problems I've had :

  • The Entire Solution search (Shift-Ctrl-F in VS) does not search in the included files, because they are not listed as source files.

  • I had to manually indicate them for Subversion inclusion.

Do you believe that including source files in other sources is an accepted workaround when files go really big ? I should say that splitting the implemented class in smaller classes is not an option here.

like image 412
Wartin Avatar asked Nov 27 '22 15:11

Wartin


1 Answers

There are times when it's okay to include an implementation file, but this doesn't sound like one of them. Usually this is only useful when dealing with certain auto-generated files, such as the output of the MIDL compiler. As a workaround for large files, no.

You should just add all of those source files to your project instead of #including them. There's nothing wrong with splitting a large class into multiple implementation files, but just add them to your project, including them like that doesn't make much sense.

-- Also, as an FYI, you can add files to your projects, and then instruct the compiler to ignore them. This way they're still searchable. To do this, add the file to the project, then right-click it, and go to Properties, and under "General" set "Exclude from Build" to Yes.

like image 136
Gerald Avatar answered Dec 05 '22 21:12

Gerald