c++ - boost serialization of struct derived from struct list -
I'm not sure how I can serial a string that comes from another type of list type. Below is sample code for what I am asking:
// nodes. Http
#include & lt; Boost / serialization / serialization.hpp & gt; #include & lt; Boost / serialization / access.hpp & gt; #include & lt; Boost / serialization / optional.hpp & gt; #include & lt; Boost / serialization / list.hpp & gt; Struct node {std :: string firstname; Std :: string lastname; Private: Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; First name; R & A last name; }}; Structure nodes: Public stadium :: List & lt; Node & gt; {Std :: String Address; Std :: string country; Private: Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; Addressing; R & A Country; }}; BOOST_CLASS_EXPORT_KEY (node); BOOST_CLASS_EXPORT_KEY (nodes); BOOST_CLASS_EXPORT_IMPLEMENT (nodes); BOOST_CLASS_IMPLEMENTATION (nodes, promote: :: ordering :: object_serializable); BOOST_CLASS_TRACKING (promoting nodes, :: ordering :: track_never); Please refer to the "public std :: list" line and tell me if my serialization is correct or not.
I do not know what you wanted to ask. Although I know
- It is not recommended to do the latter from standard containers (they were not designed for it)
-
If You do, you still need to specify that you want to serialize the base class: Structure nodes: public stadium :: list & lt; Node & gt; {Std :: String Address; std :: string country; Private: Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; Promote :: Ordering :: base_object & LT; std :: from the list & lt; Node & gt; & Gt; (* this); R & A Addressing; R & A Country; }}; Of course, I list a member a base . Do not Forget To Include boost / serialization / list.hpp : See this #include & lt; Boost / serialization / serialization HPP & gt; # Include & lt; Boost / archive / text_oarchive.hpp & gt; #include & lt; Boost / serialization / export.hpp & gt; #include & lt; Boost / serialization / access.hpp & gt; #include & lt; Boost / serialization / base_object.hpp & gt; #include & lt; Boost / serialization / optional.hpp & gt; #include & lt; Boost / serialization / list.hpp & gt; #include & lt; Boost / serialization / shared_ptr.hpp & gt; # Include & lt; List & gt; Struct node {std :: string firstname; Std :: string lastname; Private: Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; First name; R & A last name; }}; Structure nodes: Public stadium :: List & lt; Node & gt; {std :: string address; Std :: string country; Private: Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; Promote :: Ordering :: base_object & LT; std :: from the list & lt; Node & gt; & Gt; (* this); R & A Addressing; R & A Country; }}; BOOST_CLASS_EXPORT_KEY (node); BOOST_CLASS_EXPORT_KEY (nodes); BOOST_CLASS_EXPORT_IMPLEMENT (nodes); BOOST_CLASS_IMPLEMENTATION (nodes, boost :: serialization :: object_serials); BOOST_CLASS_TRACKING (nodes, boost: serialization :: track_overre); Int main () {boost :: archive :: text_oarchive oa (std :: cout); Nodes nodes; Nodes.address = "Mister"; Nodes.country = "Puerto Mazareki"; Nodes .incent (nodesend), node {"john", "dow"}); Nodes.incent (nodesend), node {"jane", "greenwall"}); Nodes .incent (nodesend.), Node {"morgan", "cheese"}); Nodes.incent (nodesend), node {"walton", "vice"}); O & lt; & Lt; Nodes; }
Comments
Post a Comment