Delete expression

自闭症网瘾萝莉.ら 提交于 2019-12-04 12:25:53

As I'm writing this your text says "Reference [here][1]" with no reference.

But essentially, the standard allows you to delete a pointer to incomplete type so that you can leverage knowledge that the compiler doesn't have, namely that the type's destructor does nothing.

std::auto_ptr is an example where this is a problem, especially for the PIMPL idiom (an infamous example of getting it wrong was Herb Sutter's GOTW on PIMPL, where he incorrectly used std::auto_ptr). boost::shared_ptr is an example where it isn't a problem (in general). That's because the constructor of boost::shared_ptr stores a deleter function, and the complete type of the pointee must necessarily be known at the point of construction.

Cheers & hth.,

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