<legend id='ylCgV'><style id='ylCgV'><dir id='ylCgV'><q id='ylCgV'></q></dir></style></legend>

        <small id='ylCgV'></small><noframes id='ylCgV'>

        <i id='ylCgV'><tr id='ylCgV'><dt id='ylCgV'><q id='ylCgV'><span id='ylCgV'><b id='ylCgV'><form id='ylCgV'><ins id='ylCgV'></ins><ul id='ylCgV'></ul><sub id='ylCgV'></sub></form><legend id='ylCgV'></legend><bdo id='ylCgV'><pre id='ylCgV'><center id='ylCgV'></center></pre></bdo></b><th id='ylCgV'></th></span></q></dt></tr></i><div id='ylCgV'><tfoot id='ylCgV'></tfoot><dl id='ylCgV'><fieldset id='ylCgV'></fieldset></dl></div>
          <bdo id='ylCgV'></bdo><ul id='ylCgV'></ul>

      1. <tfoot id='ylCgV'></tfoot>
      2. boost::shared_ptr 和 std::shared_ptr 的同居

        Cohabitation of boost::shared_ptr and std::shared_ptr(boost::shared_ptr 和 std::shared_ptr 的同居)
      3. <legend id='n9D2x'><style id='n9D2x'><dir id='n9D2x'><q id='n9D2x'></q></dir></style></legend>
          <tbody id='n9D2x'></tbody>
          <bdo id='n9D2x'></bdo><ul id='n9D2x'></ul>
        • <tfoot id='n9D2x'></tfoot>

                <small id='n9D2x'></small><noframes id='n9D2x'>

                <i id='n9D2x'><tr id='n9D2x'><dt id='n9D2x'><q id='n9D2x'><span id='n9D2x'><b id='n9D2x'><form id='n9D2x'><ins id='n9D2x'></ins><ul id='n9D2x'></ul><sub id='n9D2x'></sub></form><legend id='n9D2x'></legend><bdo id='n9D2x'><pre id='n9D2x'><center id='n9D2x'></center></pre></bdo></b><th id='n9D2x'></th></span></q></dt></tr></i><div id='n9D2x'><tfoot id='n9D2x'></tfoot><dl id='n9D2x'><fieldset id='n9D2x'></fieldset></dl></div>

                • 本文介绍了boost::shared_ptr 和 std::shared_ptr 的同居的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在某个时候使用 boost::log,但我不能将 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?

                  我不认为它与这个问题重复表示两者是相同的.

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

                  推荐答案

                  你可以这样做:

                  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!

                  这篇关于boost::shared_ptr 和 std::shared_ptr 的同居的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                        <tbody id='oRuOO'></tbody>
                    1. <i id='oRuOO'><tr id='oRuOO'><dt id='oRuOO'><q id='oRuOO'><span id='oRuOO'><b id='oRuOO'><form id='oRuOO'><ins id='oRuOO'></ins><ul id='oRuOO'></ul><sub id='oRuOO'></sub></form><legend id='oRuOO'></legend><bdo id='oRuOO'><pre id='oRuOO'><center id='oRuOO'></center></pre></bdo></b><th id='oRuOO'></th></span></q></dt></tr></i><div id='oRuOO'><tfoot id='oRuOO'></tfoot><dl id='oRuOO'><fieldset id='oRuOO'></fieldset></dl></div>

                      <tfoot id='oRuOO'></tfoot>

                      1. <small id='oRuOO'></small><noframes id='oRuOO'>

                        • <legend id='oRuOO'><style id='oRuOO'><dir id='oRuOO'><q id='oRuOO'></q></dir></style></legend>
                            <bdo id='oRuOO'></bdo><ul id='oRuOO'></ul>