升压:: shared

编程入门 行业动态 更新时间:2024-10-25 04:25:43
本文介绍了升压:: shared_ptr的和std :: shared_ptr的同居的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用的boost ::登录在某些时候,但我不能传递的std :: shared_ptr的作为参数,因为编译器(VS2010)无法将其转换成的boost :: shared_ptr的。

I want to use boost::log at some point, but I cannot pass a std::shared_ptr as a parameter, because the compiler (VS2010) cannot convert it into a boost::shared_ptr.

我真的不喜欢的事实,他们是外星人彼此。

I don't really like the fact that they are aliens to one another.

有一个转换成另一个,以便它们不绊倒彼此安全和透明的方式?

Is there a safe and transparent way to convert one into the another, so as they don't stumble over each other?

我不认为这是重复的this问题的,各国都是一样的。

I don't think it is duplicate of this question that states both are the same.

推荐答案

您可以做到这一点是这样的:

You could do it like this:

template<typename T> boost::shared_ptr<T> make_shared_ptr(std::shared_ptr<T>& ptr) { return boost::shared_ptr<T>(ptr.get(), [ptr](T*) mutable {ptr.reset();}); } template<typename T> std::shared_ptr<T> make_shared_ptr(boost::shared_ptr<T>& ptr) { return std::shared_ptr<T>(ptr.get(), [ptr](T*) mutable {ptr.reset();}); }

编辑:请注意,这不与向源PTR弱引用工作。所以,要小心那些!

Note that this does not work with weak references to the source ptr. So be careful with those!

更多推荐

升压:: shared

本文发布于:2023-07-30 00:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244946.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:shared

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!