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

青灯夜游
Release: 2022-01-12 15:49:04
Original
20441 people have browsed it

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. Theheader 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 forsource code calls.can be #included by #include compilation preprocessing instructions in thesource 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 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(){} }
Copy after login

These contents are placed in the .h file

void T:showName(){}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!