简体   繁体   English

为什么 pow() 不输入“使用 std::pow();”就可以工作还是“std::pow(x,y);”?

[英]Why does pow() work without typing “using std::pow();” or “std::pow(x,y);”?

I can use pow() with #include <cmath> and without the using keyword or the :: operator.我可以将pow()#include <cmath>一起使用,而无需using关键字或::运算符。 Why?为什么?

From [headers]/4 of the standard.来自标准的[headers]/4

Except as noted in Clause 20 through Clause 33 and Annex D, the contents of each header cname is the same as that of the corresponding header name.h as specified in the C standard library (Clause 2).除第 20 条至第 33 条和附件 D 中另有说明外,每个 header cname的内容与 Z0D61F8370CAD1D412F70B84D 中指定的相应 header name.h的内容相同()。 In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (6.3.6) of the namespace std.然而,在 C++ 标准库中,声明(在 C 中定义为宏的名称除外)位于命名空间 std 的命名空间 scope (6.3.6) 中。 It is unspecified whether these names (including any overloads added in Clause 21 through Clause 33 and Annex D) are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (10.3.3).未指定这些名称(包括在第 21 条至第 33 条和附件 D 中添加的任何重载)是否首先在全局命名空间 scope 中声明,然后通过显式使用声明(10.3.3) 注入命名空间 std。

Basically, the standard allows functions within the c headers to be part of the global scope;基本上,该标准允许c标头中的功能成为全局 scope 的一部分; however, they aren't required to be.但是,它们不是必须的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM