Is it safe to delete a POD object by a pointer to its base?

▼魔方 西西 提交于 2019-12-05 02:11:43

No, this is not allowed. [expr.delete]/p3, emphasis mine:

In the first alternative (delete object), if the static type of the object to be deleted is different from its dynamic type, the static type shall be a base class of the dynamic type of the object to be deleted and the static type shall have a virtual destructor or the behavior is undefined.

In fact, the committee fairly recently rejected a proposal to make deleting a POD via a pointer-to-base well-defined.

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