CVRIV wrote: |
---|
it's getting annoyingly large in size where im having to scroll through lines and lines of code to get anywhere. |
I was under impression that some editors are able to show "table of contents"/"index" that makes it easier to jump to code of specific function, etc.
(I'm quite sure it was possible in previous millennium ...)
A core concept is "
translation unit". One (cpp-file) is compiled into one object file.
A project/program can have multiple translation units, i.e. multiple cpp-files that are compiled separately.
Linker combines the object files into executable binary of the program.
A translation unit is not "just" the cpp-file. It has also all the content that the preprocessor includes. Content from the header files.
Second important point is ODR,
One Definition Rule. Objects can be defined only once among all the object files that are linked together.
Implementation of a function and global variable are such "objects". If you define them in header and include that header in more than one cpp-file, then more than one translation unit will contain that definition, which violates ODR.
Note though that
class definition is not such thing. Description of a type is not object code. It is just instruction for compiler for generating object code for object instances of that type.
In other words, headers have what multiple cpp-files need to know. Knowledge that they can share.
Another peculiarity are the templates. Template for implementation of a function is not "object" either. It is ok to instantiate a concrete function with same type in multiple translation units. Linker knows how to avoid that multiple definition.