Boost logo

Boost Users :

Subject: Re: [Boost-users] boost_serialization ok with vector<int> but not with vector<int *>
From: Tony Camuso (tcamuso_at_[hidden])
Date: 2015-03-06 20:27:51


On 03/06/2015 07:42 PM, Robert Ramey wrote:
> Tony Camuso wrote
>> Why is the compiler okay with ...
>> std::vector
>> <int>
>> intvec;
>> ... but throws an error for ...
>> std::vector
>> <int *>
>> pintvec;
>
> The answer can be found here:
>
> </a> <http://>
> http://stackoverflow.com/questions/19076299/how-do-i-serialize-a-class-containing-pointers-to-primitives
>
> I concede that this should be added to the documentation. Feel free to
> open a trac item to remind me of this.
>
> So the solution is to wrap your int inside a class. This will give it a
> unique type and distinguish from all the other int instances you don't
> really want to track. Also you can use BOOST_SERIALIZATION to create a
> wrapper.
>

Thanks, Robert.

Wasn't aware of the BOOST_SERIALIZATION macro. I'll look it up.

Another question. It seems that attempts to serialize containers of pointers
of any kind throw compiler errors. For example,

std::vector<string> str; // compiler is ok with serializing this

std::vector<string *> pstr; // compiler throws an error

The documentation gave me the impression that the serialization lib would
dereference the pointers correctly, and perform all the housekeeping around
that. Also got the impression that nothing special had to be done for the
deserialize step.

Is my reading comprehension off? :)

Thanks again for your help.

  

>
>
>
> --
> View this message in context: http://boost.2283326.n4.nabble.com/Flood-of-messages-when-building-with-boost-serialization-tp4672684p4672804.html
> Sent from the Boost - Users mailing list archive at Nabble.com.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net