destructors to prevent resource leaks. (More Effective C++)

The solution is to replace the pointer pa with an object that acts like a pointer. That way, when the pointer-like object is (automatically) destroyed, we can have its destructor call delete. Objects that act like pointers, but do more, are called smart pointers, and, as Item 28 explains, you can make pointer-like objects very smart indeed. In this case, we don't need a particularly brainy pointer, we just need a pointer-like object that knows enough to delete what it points to when the pointer-like object goes out of scope. 

原文链接: https://www.cnblogs.com/zhtf2014/archive/2011/06/14/2080626.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    destructors to prevent resource leaks. (More Effective C++)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/27189

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午4:46
下一篇 2023年2月8日 上午4:46

相关推荐