What is the difference between a .cpp file and a .h file?(.cpp 文件和 .h 文件有什么区别?)
问题描述
因为我已经制作了 .cpp 文件,然后将它们转换为 .h 文件,所以我能找到的唯一区别是您不能 #include .cpp 文件.我缺少什么区别吗?
Because I've made .cpp files then transfered them into .h files, the only difference I can find is that you can't #include .cpp files. Is there any difference that I am missing?
推荐答案
C++ 构建系统(编译器)没有区别,所以都是一种约定.
The C++ build system (compiler) knows no difference, so it's all one of conventions.
约定是.h
文件是声明,.cpp
文件是定义.
The convention is that .h
files are declarations, and .cpp
files are definitions.
这就是为什么 .h
文件是 #include
d -- 我们包含声明.
That's why .h
files are #include
d -- we include the declarations.
这篇关于.cpp 文件和 .h 文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.cpp 文件和 .h 文件有什么区别?


基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01