Make interchangeable class types via pointer casting only, without having to allocate any new objects?

前端 未结 4 1144
半阙折子戏
半阙折子戏 2020-12-17 04:24

UPDATE: I do appreciate \"don\'t want that, want this instead\" suggestions. They are useful, especially when provided in context of the motivating scenari

4条回答
  •  清酒与你
    2020-12-17 05:20

    I believe the strict aliasing rules forbid what you are trying to do.

    To clarify: strict aliasing has nothing to do with layout compatibility, POD types or what not. It has to do with optimization. And with what the language explicitly forbids you to do.

    This paper sums it up rather well: http://dbp-consulting.com/StrictAliasing.pdf

提交回复
热议问题