shared_dynamic_cast 和dynamic_pointer_cast 之间的区别
之间的区别吗
有人可以向我解释Boost 库中的 shared_dynamic_cast
和 dynamic_pointer_cast
?在我看来,它们可能是等效的。
Can someone explain to me the difference between:
shared_dynamic_cast
and dynamic_pointer_cast
from the Boost library?
It appears to me that they may be equivalent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定一个
shared_ptr
,这两个函数确实是等价的。区别在于,
shared_dynamic_cast
仅适用于shared_ptr<>
,而dynamic_pointer_cast
适用于任何类型的指针(通过重载)。这使您能够对任何指针概念执行动态转换,无论该指针的实际组成方式如何:因为
dynamic_pointer_cast
具有shared_dynamic_cast
的功能此外,后一个函数已被弃用。 (同样,在 C++11 中,只存在dynamic_pointer_cast
。)(当然,对于其他强制转换变体,这个想法也是相同的。)
Given a
shared_ptr<T>
, the two functions are indeed equivalent.The difference is that
shared_dynamic_cast
only works withshared_ptr<>
's, whiledynamic_pointer_cast
works with any kind of pointer (via overloading). This enables you to perform a dynamic cast on any pointer concept, regardless of how that pointer is actually composed:Because
dynamic_pointer_cast
has the capability ofshared_dynamic_cast
and more, the latter function is deprecated. (Likewise in C++11, there only existsdynamic_pointer_cast
.)(The idea is the same for the other cast variants too, of course.)