Get address of a non-POD object from within a data member, which is a single-use nested class

﹥>﹥吖頭↗ 提交于 2019-12-04 19:20:28

This code does not work, per the C++ specification, for several reasons:

  1. offsetof requires a POD type (in C++11, it requires a standard-layout type). Your type is not, and therefore calling it results in undefined behavior.
  2. The conversion to int8_t* and then to another type is undefined behavior per the C++ specification. You would need to use a char*, which has certain relaxed casting rules.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!