包括的.cpp,而不是头文件(.h) [英] Include .cpp instead of header(.h)

查看:241
本文介绍了包括的.cpp,而不是头文件(.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?

怎么样的编译时间?

推荐答案

这是懒惰的编码。使用头文件。是的,他们可以增加编译时间,但他们的意思是,你可以很容易地重新实现你的code大块,或更好,但可能随时另一家开发商。头文件作为你的什么C / C ++ code会做一个模板。这是一个坏主意,放弃或忽略它。

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,而不是头文件(.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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