Suppose you are creating a class with multiple .cpp files (which each contain the implementation of a member function) and have the class’ declaration in a .h file. Also, each .cpp file includes the .h file via the include directive.
I was told that if you change the implementation of any of the member functions (.cpp files) that you will have to recompile every .cpp file in order to run the program. That is, if I had 5 member functions (each implemented in a .cpp file) and I changed the implementation of 1 of the .cpp files I would have to compile the 1 .cpp file I changed AND the 4 other .cpp files I didn’t change in order to correctly run my program.
My question, if the previous statement is true, is why is the statement is true? Any insight on this concept would be helpful.
It’s false. If there is no change to a particular implementation file, no change to header files it includes, and no changes to the environment or compiler options, there is absolutely no need to recompile it. Everything that affects the compilation of that file hasn’t changed.
In fact, you can compile each of the files without even having any of the others at all. Then you can link all the compiled files together without all the implementation files ever having been in the same place.