intrusive_ptr:为什么没有一个共同的基类提供? [英] intrusive_ptr: Why isn't a common base class provided?

查看:216
本文介绍了intrusive_ptr:为什么没有一个共同的基类提供?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的boost :: intrusive_ptr intrusive_ptr_add_ref intrusive_ptr_release < /一>中定义。为什么是不是一个基类,设置能做到这一点?这里有一个例子: http://lists.boost.org/Archives /boost/2004/06/66957.php ,但海报上写着我并不认为这是个好主意。为什么不呢?

boost::intrusive_ptr requires intrusive_ptr_add_ref and intrusive_ptr_release to be defined. Why isn't a base class provided which will do this? There is an example here: http://lists.boost.org/Archives/boost/2004/06/66957.php, but the poster says "I don't necessarily think this is a good idea". Why not?

更新:我不认为的事实,这类可以使用多重继承被误用足够的理由。从多个基类派生自己的引用计数的任何类也有同样的问题。无论这些引用计数通过一个基类的实现与否没什么区别。

Update: I don't think the fact that this class could be misused with Multiple Inheritance is reason enough. Any class which derives from multiple base classes with their own reference count would have the same issue. Whether these refcounts are implemented via a base class or not makes no difference.

我不认为有一个与多线程的任何问题; 的boost :: shared_ptr的 提供原子引用计数和这个类可以了。

I don't think there's any issue with multithreading; boost::shared_ptr offers atomic reference counting and this class could too.

推荐答案

这是所以你可以使用intrusive_ptr使用类已经实现新增和释放。

It's so you can use intrusive_ptr with classes that already implement add and release.

这篇关于intrusive_ptr:为什么没有一个共同的基类提供?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆