包含 .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.
相关文章