Does the standard mandate enable_shared_from_this is to be inherited publicly? Why?

半城伤御伤魂 提交于 2019-12-01 17:46:31

Since private enable_shared_from_this + friend shared_ptr seems to cover this use case, shouldn't it be sufficient by the standard?

No. The standard permits implementations wide latitude with how they implement things. The constructor of shared_ptr<T> that adopts an object may defer the shared-from-this stuff to some helper function or other object. For maximum irony, it could defer to a base class of shared_ptr<T> ;)

As such, enable_shared_from_this must be accessible by any code in order for the shared_ptr constructor to work.

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