|
Boost Users : |
Subject: Re: [Boost-users] [serialization] Different behaviors between archive and its polymorphic variant
From: Maxime van Noppen (maxime_at_[hidden])
Date: 2010-08-19 04:52:54
On 08/18/2010 08:33 PM, Robert Ramey wrote:
>
>>> So now 'unit' only has a template serialize method, but I still
>>>
>>>> int main()
>>>> {
>>>> unit u(42);
>>>>
>>>> {
>>>> std::cout << "template:" << std::endl;
>>>> test_oarchive ar(std::cout);
>>>> ar << BOOST_SERIALIZATION_NVP(u);
>>>> std::cout << std::endl;
>>>> }
>>>>
>>>> {
>>>> std::cout << "polymorphic:" << std::endl;
>>>> polymorphic_test_oarchive ar(std::cout);
>>>> ar << BOOST_SERIALIZATION_NVP(u);
>>>> std::cout << std::endl;
>>>> }
>>>> }
>>>
>>> Which outputs:
>>>
>>>> template:
>>>> <name=u><name=id_>42</name=id_>
>>>> </name=u>
>>>>
>>>> polymorphic:
>>>> 42
>>>
>>> Code is attached.
>
> what happens when you try:
>
> std::cout << "polymorphic:" << std::endl;
> polymorphic_oarchive & po = polymorphic_test_oarchive ar(std::cout);
> po << BOOST_SERIALIZATION_NVP(u);
> std::cout << std::endl;
>
> This would actually be using the polymorphic interface as it's
> intended to be used by routing the serialization through the polymorphic
> interface.
>
> Robert Ramey
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
I added:
> {
> std::cout << "polymorphic with polymorphic_oarchive:" << std::endl;
> polymorphic_test_oarchive ar(std::cout);
> boost::archive::polymorphic_oarchive & po = ar;
> po << BOOST_SERIALIZATION_NVP(u);
> std::cout << std::endl;
> }
The output is:
> template:
> <name=u><name=id_>42</name=id_>
> </name=u>
>
> polymorphic:
> 42
> polymorphic with polymorphic_oarchive:
> 42
-- Maxime
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