包含 .cpp 而不是 header(.h) [英] Include .cpp instead of header(.h)

查看:40
本文介绍了包含 .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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆