Include .cpp instead of header(.h)(包含 .cpp 而不是 header(.h))
问题描述
在某些情况下,我们包含 .cpp 文件而不是标准头文件 (.h),例如:
There are some cases when we include .cpp file instead of standard header file (.h), for example:
#include "example.cpp"
代替
#include "example.h"
它似乎有效,但这是否安全还是我应该避免它?
It seems to work but is this safe or should I avoid it?
编译时间呢?
推荐答案
这是懒惰的编码.使用头文件.是的,它们可以增加编译时间,但它们意味着您可以轻松地重新实现代码块,或者更好的是,其他开发人员可以随时重新实现.头文件用作 C/C++
代码将要执行的操作的模板.丢弃或忽略它是一个坏主意.
It's lazy coding. Use header files. Yes they can increase compile time but they mean that you can easily re-implement chunks of your code, or better yet, another developer could at anytime. The header file serves as a template for what your C/C++
code is going to do. It's a bad idea to discard or ignore it.
这篇关于包含 .cpp 而不是 header(.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包含 .cpp 而不是 header(.h)


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