Difference: The header file is a ".h" file, which provides the interface; the source file is a ".cpp" file, which provides the implementation. The compiler stipulates that the source file must contain the function entry, that is, the main function; the header file must not contain the function entry. The header file cannot be compiled into a program alone, and only contains program fragments or defined constants and variables.
#The operating environment of this article: Windows 7 system, Dell G3 computer.
Related recommendations: "C Video Tutorial"
Difference:
General For example, the header file provides the interface, and the source file provides the implementation
The compiler stipulates that the source file must contain the function entry, that is, the main function. The header file must not contain function entries, and the header file cannot be compiled into a program alone, and only contains program fragments or defined constants and variables.
The header file is a static include file specially written for source code calls. can be #included by #include compilation preprocessing instructions in the source code file. Explanation, If the header file is complete and copied to the instruction of the source code, compilation is equivalent to inserting a function declaration or implementation into the source code.
Header files and source files
Header files are .h files, which generally contain class declarations. The #include
The source file is the .cpp file, which is generally used to implement the specific implementation of the class member functions declared in the header file. Generally, a .h file will always have a .cpp with the same name
For example: a class
class T{ void showName(){} }
These contents are placed in the .h file
void T:showName(){}
These contents are placed in For more programming-related knowledge in
in the .cpp file, please visit: Programming Teaching! !
The above is the detailed content of What is the difference between header files and source files in c++. For more information, please follow other related articles on the PHP Chinese website!