Is converting a reinterpret_cast'd derived class pointer to base class pointer undefined behavior?

后端 未结 4 1308
故里飘歌
故里飘歌 2021-02-08 04:53

Have a look at is simple example:

struct Base { /* some virtual functions here */ };
struct A: Base { /* members, overridden virtual functions */ };
struct B: Ba         


        
4条回答
  •  逝去的感伤
    2021-02-08 05:36

    Yes, It does have undefined behavior. The layout about suboject of Base in A and B is undefined. x may be not a real Base oject.

提交回复
热议问题