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

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

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

        boost::serialization 如何与 C++11 中的 std::shared_ptr 一起使用?

        How can boost::serialization be used with std::shared_ptr from C++11?(boost::serialization 如何与 C++11 中的 std::shared_ptr 一起使用?)
          <tbody id='QcQae'></tbody>

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

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

            <legend id='QcQae'><style id='QcQae'><dir id='QcQae'><q id='QcQae'></q></dir></style></legend>
              1. <tfoot id='QcQae'></tfoot>

                  本文介绍了boost::serialization 如何与 C++11 中的 std::shared_ptr 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道有一个Boost模块序列化的boost::shared_ptr,但我找不到任何东西对于 std::shared_ptr.

                  另外,我不知道如何轻松实现它.恐怕下面的代码

                  Also, I don't know how to implement it easily. I'm afraid that the following code

                  namespace boost{namespace serialization{
                  template<class Archive, class T>
                  inline void serialize(Archive & ar, std::shared_ptr<T> &t, const unsigned int version)
                  {
                    if(Archive::is_loading::value) {T*r;ar>>r;t=r;}
                    else {ar<<t.get();}
                  }
                  }}//namespaces
                  

                  不起作用.事实上,如果某个对象被多次引用,它将在第一次运行 ar>>r 时加载,然后只复制一个指针.然而,我们会创建多个指向它的 shared_ptr 对象,因此会多次破坏它.

                  doesn't work. Indeed, if some object was referred multiple times, it would be loaded with first run of ar>>r, and after that just a pointer will be copied. However we would create multiple shared_ptr objects pointing to it, and therefore would destruct it more than one time.

                  对此有什么想法吗?

                  关于我正在使用的系统的一些技术细节:

                  Some technical details about the system I'm using:

                  • 操作系统:Ubuntu 11.10 (x64)
                  • 编译器:g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
                  • boost 版本:1.46.1(使用 sudo apt-get install libboost-dev 安装)

                  推荐答案

                  从 Boost 1.56 开始,序列化库有 对 std::shared_ptr 的内置支持.如果您可以使用该库的更新版本,则无需实现自己的序列化辅助函数.

                  As of Boost 1.56, the serialization library has built-in support for std::shared_ptr. You do not need to implement your own serialization helper functions if you can use a more recent version of the library.

                  这篇关于boost::serialization 如何与 C++11 中的 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自动链接如何做出选择?)

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

                    <tbody id='USJSF'></tbody>

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