在Qt 4.8中使用没有命名空间的memcpy(use memcpy without namespace in Qt 4.8)

编程入门 行业动态 更新时间:2024-10-26 23:29:27
在Qt 4.8中使用没有命名空间的memcpy(use memcpy without namespace in Qt 4.8)

在Qt 4.8中

当我#include <cstring> ,我发现我可以直接使用memcpy 。

为什么我不需要使用std::memcpy呢?

为什么编译器不报告错误?

In Qt 4.8

When I #include <cstring>, I found that I can use memcpy directly.

Why should I not need to use std::memcpy instead?

Why the complier does not report an error?

最满意答案

标准说(§17.5.1.2/ 4)

除第17至30条和附录D中所述外,每个标题cname的内容与C标准库(1.2)中指定的相应标题name.h的内容相同。 但是,在C ++标准库中,声明(除了在C中定义为宏的名称除外)都在命名空间std的命名空间范围(3.3.6)内。 未指定这些名称(包括第18至30条和附件D中添加的任何重载)是否首先在全局命名空间范围内声明,然后通过显式使用声明(7.3.3)注入命名空间std。

因此,当您包含<cstring> ,名称在名称空间std::可用,但允许名称也在全局名称空间中。

同样,当您包含<string.h>该名称保证在全局名称空间中,但也可能在名称空间std可见。

The standard says (§17.5.1.2/4)

Except as noted in Clauses 17 through 30 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 (1.2). In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names (including any overloads added in Clauses 18 through 30 and Annex D) are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (7.3.3).

So when you include <cstring> the name is available in namespace std::, but it is allowed for the name to also be in the global namespace.

Likewise, when you include <string.h> the name is guaranteed to be in the global namespace, but might also be visible in namespace std.

更多推荐

本文发布于:2023-07-08 00:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1070190.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空间   Qt   memcpy   namespace

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!