Why are function bodies in C / C ++ placed in separate source code files instead of headers?

For example, when I define a class file in C ++, I always put function bodies in the class header files (.h) along with the class definition. The source code file (.cpp) is a file with the main () function. Now this is usually done among C ++ programmers or they follow the convention of the individual header / source files.

As for Native C, I notice that this is done in GCC (and, of course, for headers in Visual Studio for Windows).

So is it just a convention? Or is there a reason for this?

+6
source share
3 answers

.cpp :

  • , , , . , , .

    , , , , .

  • . , , , .

    , (.. ), , , , ( ).

  • "" (.. , ).

  • , , . , "" , .

    , inline , (.. ) , ( ) .

  • , .

+17

, . , , , (), , header only, (s).

; , , , . - .. , , , , . , , - . , , .

, , , . .

, , , , , . .

+4

'c'. 'c', . "", , , .

++. "" .

cpp, .

+1

All Articles