gpt4 book ai didi

C++ 标准布局和引用

转载 作者:可可西里 更新时间:2023-11-01 18:26:38 26 4
gpt4 key购买 nike

根据C++标准:

A standard-layout class is a class that:

—has no non-static data members of type non-standard-layout class (or array of such types) or reference.

引用的哪些属性会阻止具有引用成员的类包含在标准布局类的定义中?

最佳答案

标准布局类就是在内存 中为特定类型定义良好的布局。在 C++ 中,引用不是对象,因此没有任何存储空间可以由符合规范的程序以明确定义的方式访问,即使实现通常必须为它们提供某种特定于实现的存储空间。

因此,在必须具有标准 布局的内容中使用引用成员是没有意义的。

标准中关于C++内存模型的部分有一个非规范的注释提到了这一点:

[ Note: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation. —end note ]

关于C++ 标准布局和引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15994042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com