c++ - 您是否需要显式包含其他 header 已包含的 header ?

标签 c++ header include

给定一个头文件foo.h:

#include <bar>

// ...

还有一个文件baz.cpp:

#include "foo.h"

// ...

是否需要将 bar header 显式包含到 baz.cpp 中才能使用它?还是您可以开始使用它,因为它包含在 foo.h 中?

最佳答案

您需要添加 #include <algorithm>main.cpp如果main.cpp使用任何函数或类,或在 <algorithm> 中定义的任何其他内容.

其他一些翻译单元使用什么是无关紧要的。

关于c++ - 您是否需要显式包含其他 header 已包含的 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39322657/

相关文章:

c++ - STL 算法中跨函数边界的循环重新排序

c++ - 如何通过 KIT 编译收缩层次结构?

c - 编译 main.c 文件时收到警告

c++ - C1083 : Cannot open include file: math. h: 没有那个文件或目录

C++ 在 2D std::vector 中找到最大值的位置

c++ - 关于C++头文件的简单问题

c++ - 我在 C 中有相互依赖的 header ,这给了我错误。我怎样才能删除它?

c - "undefined reference to"C header 中的一个函数,但不是另一个函数

来自多个位置的 C 包含文件

Android 包含在布局的底部