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)


基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01