为什么发生在一个单独的目录标题? [英] Why place headers in a separate directory?

查看:86
本文介绍了为什么发生在一个单独的目录标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,这是在C / C ++项目共同放置在一个目录中的头文件,如包含,并在一个单独的目录执行,如 SRC 。我一直在玩弄不同的项目结构,我想知道是否有这方面的任何客观原因还是纯粹约定?

I know that it is common in C/C++ projects to place header files in a directory such as include and implementation in a separate directory such as src. I have been toying with different project structures and am wondering whether there any objective reasons for this or is it simply convention?

推荐答案

公约的原因之一 - 大部分的时间,有效的抽象,你只关心接口,并希望有更容易只看标题

Convention is one of the reasons - most of the time, with effective abstraction, you only care about the interface and want to have it easy just looking at the headers.

这不,虽然唯一的原因。如果您的项目在模块组织,你极有可能包含不同的模块一些头,你希望你的include目录中有被清洗的其他的噪音的文件。

It's not the only reason though. If your project is organised in modules, you most likely have to include some headers in different modules, and you want your include directory to be cleaned of other "noise" files in there.

另外,如果你打算重新分配你的模块,你可能想隐藏实现细节。所以,你只提供头文件和二进制文件 - 从一个单一的文件夹,并分发头有没有别的更简单

Also, if you plan on redistributing your module, you probably want to hide implementation details. So you only supply headers and binaries - and distributing headers from a single folder with nothing else in it is simpler.

还有替代我居然preFER - 公头去在一个单独的文件夹(其中包含最小的界面 - 没有实现细节可见任何),和私有头和实现文件是分开的(可能,但不一定,在单独的文件夹)。

There's also an alternative which I actually prefer - public headers go in a separate folder (these contain the minimum interface - no implementation details are visible whatsoever), and private headers and implementation files are separate (possibly, but not necessarily, in separate folders).

这篇关于为什么发生在一个单独的目录标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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