Static method to create an object instead of constructor

本秂侑毒 提交于 2019-12-05 04:17:01

The is a classic use of a Factory for making objects.

That said, you might not need this. Do you know when widgets are no longer needed? GUI managers like this often do. If so, the commenter is right: designate an owner of the object, let it delete it, and you're set.

You could consider inheriting from enable_shared_from_this.

Then after you have a shared_ptr to the object, you can use shared_from_this() to get the shared_ptr that holds the object.

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