C++ Standard Layout and References

喜你入骨 提交于 2019-12-05 05:14:56

A standard layout class is all about having a well defined layout for a particular type in memory. In C++, references aren't objects so don't have any storage that can be accessed in a well defined way by a conforming program even though the implementation will usually have to have some sort of implementation specific storage for them.

For this reason it doesn't make sense to have reference members in something that must have a standard layout.

There's a non-normative note in the standard in the section about the C++ memory model that mentions this:

[ 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 ]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!