1: Only the class declaration code in a.h is included in the class b file After the program is compiled, all the compiled files will be linked into an executable file, which is equivalent to summarizing all the codes So you only need to include the declaration 2: Each cpp is compiled separately If there is a connection between different cpps, such as a.cpp calling a function in b.cpp, after b.cpp changes, only b.cpp will be compiled cpp
contains the content in a.h. If there is an implementation in a.h, then there is an implementation.
The specific action of compilation takes Linux as an example. You can use cc -E a.cpp to see the results after preprocessing. Each .cpp file will be regarded as a compilation unit and compiled to generate a .o file.
1: When including the header file .h, only the code in the header file will be included, and the corresponding .cpp will not be included. So generally only the declaration of variables or functions is provided in .h, but no implementation code is provided. Otherwise, when a header file is included by multiple .cpp, the variable or function will be reported to be repeatedly defined during linking; 2: Each cpp will be compiled separately into the corresponding .o file, and then linked together to form a Execution file or library;
1: Only the class declaration code in a.h is included in the class b file
that is related to b.cppAfter the program is compiled, all the compiled files will be linked into an executable file, which is equivalent to summarizing all the codes
So you only need to include the declaration
2: Each cpp is compiled separately
If there is a connection between different cpps, such as a.cpp calling a function in b.cpp, after b.cpp changes, only b.cpp will be compiled cpp
contains the content in a.h. If there is an implementation in a.h, then there is an implementation.
The specific action of compilation takes Linux as an example. You can use
cc -E a.cpp
to see the results after preprocessing. Each .cpp file will be regarded as a compilation unit and compiled to generate a .o file.1: When including the header file .h, only the code in the header file will be included, and the corresponding .cpp will not be included.
So generally only the declaration of variables or functions is provided in .h, but no implementation code is provided. Otherwise, when a header file is included by multiple .cpp, the variable or function will be reported to be repeatedly defined during linking;
2: Each cpp will be compiled separately into the corresponding .o file, and then linked together to form a Execution file or library;