Home  >  Article  >  Backend Development  >  What is the difference between header files and source files in c++

What is the difference between header files and source files in c++

青灯夜游
青灯夜游Original
2020-12-24 14:31:5220697browse

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.

What is the difference between header files and source files in c++

#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 #includebbed3fed50f96ac7490cfc6a498c4bc5 usually used contains this File

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn