<co*****@gmail.com> wrote:
I don't know why c++ divide source file into .cpp file and .h file.
who can tell me?
In small programs it is mainly used to provide function prototypes that may
be used by the following program.
In large programs it provides a central repository that allow a number of
..cpp files (I will call them modules here) to communicate with each other.
If you have one header file, say mwp.h, (my wonderful program) you can put
all the (home-brew) function prototypes, struct and class definitions and
other neat stuff. All the .cpp files would have an #include "mwp.h" and
it is the fundamental means of inter-module communications.
Some of the other neat stuff can include macros, enums, typedefs, forward
declarations, constants, external declarations for primitive variables used
by more than one module and perhaps more. Slovenly types can put global
variables in an .h file.