为什么似乎没有必要包含一些STL标头 [英] Why it seems not necessary to include some STL headers

查看:60
本文介绍了为什么似乎没有必要包含一些STL标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为需要包含一些标头才能使用gcc(4.9)进行编译,

I think some headers need to be included to compile with gcc(4.9),

#include <algorithm> // for std::transform
#include <numeric>   // for std::adjacent_difference

但是,我发现根本没有必要包含它们,我仍然可以致电例如,以下功能

However, I found it's not necessary include them at all, I can still call for example, the following functions

std::adjacent_difference (V1.begin(), V1.end(), V2.begin());
std::transform(V2.begin(), V2.end(), V3.begin(), V4.begin(), std::divides<double>());

也许我误解了包括头文件的机制...任何提示吗?

Maybe I have misunderstood the mechanism of including header files...Any hint?

推荐答案

一个标头包含其他标头是很典型的.标头x包含的标头将包含在任何包含x的文件中.一旦您以另一种方式掌握了文件中的包括,就应该理解这很简单.在这种情况下,其中一个标准标头恰好包含在另一个标头中.

It is quite typical for a header to include other headers. The headers included by header x will be included in any file that includes x. That should be trivial to understand once you grasp what including a file in another means. In this case, one of the standard headers happened to be included in another.

标头包含的文件可以在版本之间进行更改.如果您不包括必需的头,则程序可能会在另一个(版本的)标准库下崩溃,即使它似乎在当前实现中也可以使用.当然,这也适用于其他库.

Files included by headers can change between versions. If you don't include a required header, your program may break under another (version of) standard library even though it may appear to work in the current implementation. Of course, this applies to other libraries as well.

这篇关于为什么似乎没有必要包含一些STL标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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