有没有办法知道哪些标头会自动包含在C ++中 [英] Is there any way to know which headers are automatically included in C++

查看:92
本文介绍了有没有办法知道哪些标头会自动包含在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是此的后续问题a>表示

This is a follow-up question for this which says that


在C ++中,与C不同,标准标头允许#include其他标准标头。

In C++, unlike C, standard headers are allowed to #include other standard headers.

有没有办法知道自动包含哪些标头,因为很难猜测哪个标头中定义了哪些符号。

Is there any way to know which headers were automatically included, since it may be difficult to guess which symbols are defined in which headers.

动机:我的作业可以在我的计算机上编译并正常工作,但TA告诉我它尚未编译,需要编译几个头文件(互斥体和算法)。我如何确定以后提交的代码是防弹的。

Motivation: My homework compiles and works correctly on my computer but TA told me it was not compiling and needed couple of headers (mutex and algorithm) to compile. How I can be sure the code I submit in future be bulletproof.

我的编译器没有给出任何有关隐式声明的警告。
我正在使用 clang ++ -std = c ++ 11 来编译我的代码。

My compiler is not giving any warning about implicit declaration. I'm using clang++ -std=c++11 to compile my code.

推荐答案

标准列出了每个标头提供的符号。除此之外,没有任何保证,既没有明显使用的符号,也没有声明所有符号。您需要为每个使用的 名称添加标题。您应该依赖间接包含。

The standard lists the symbols made available by each header. There are no guarantees beyond that, neither that symbols which are obviously used nor that there not all symbols are declared. You'll need to include each header for any name you are using. You should not rely on indirect includes.

从正面看,标准库中没有任何标准库头文件的情况需要额外的标题。

On the positive side, there is no case in the standard library where any of the standard library headers requires extra headers.

这篇关于有没有办法知道哪些标头会自动包含在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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