|
Boost Users : |
From: Anders Wang Kristensen (awk_at_[hidden])
Date: 2006-11-07 04:56:35
Thanks for your swift reply!
In my example with the non-templated serialize with polymorphic_iarchive
the statement BOOST_CLASS_EXPORT(B) fails to compile. It compiles
fine without that statement, but fails to serialize with asserion:
Assertion failed: NULL != bpos_ptr, file
include\boost\archive\detail\oserializer.hpp, line 418
If I manully register B with register_type it works.
I'm using VC8 and boost 1.33.1 and I've attached the error message from
compiling.
-- Anders
1>Compiling...
1>_main.cpp
1>include\boost\serialization\access.hpp(109) : error C2664: 'void
B::serialize(boost::archive::polymorphic_iarchive &,const unsigned int)' :
cannot convert parameter 1 from 'boost::archive::text_oarchive' to
'boost::archive::polymorphic_iarchive &'
1> include\boost\serialization\serialization.hpp(81) : see reference
to function template instantiation 'void
boost::serialization::access::serialize<Archive,T>(Archive &,T &,const
unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\serialization\serialization.hpp(140) : see reference
to function template instantiation 'void
boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(152) : see reference
to function template instantiation 'void
boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(145) : while
compiling class template member function 'void
boost::archive::detail::oserializer<Archive,T>::save_object_data(boost::archive::detail::basic_oarchive
&,const void *) const'
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(163) : see reference
to class template instantiation
'boost::archive::detail::oserializer<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(162) : while
compiling class template member function 'const
boost::archive::detail::basic_oserializer
&boost::archive::detail::pointer_oserializer<T,Archive>::get_basic_serializer(void)
const'
1> with
1> [
1> T=B,
1> Archive=boost::archive::text_oarchive
1> ]
1> include\boost\archive\detail\oserializer.hpp(515) : see reference
to class template instantiation
'boost::archive::detail::pointer_oserializer<T,Archive>' being compiled
1> with
1> [
1> T=B,
1> Archive=boost::archive::text_oarchive
1> ]
1> include\boost\serialization\export.hpp(86) : see reference to
function template instantiation 'const
boost::archive::detail::basic_pointer_oserializer
&boost::archive::detail::instantiate_pointer_oserializer<Archive,T>(Archive
*,T *)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(82) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::o::invoke(void)'
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(105) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>::o' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(89) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::instantiate(void)'
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(116) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(115) : while compiling
class template member function 'void
boost::archive::detail::export_impl::for_each_archive<ASeq,T>::instantiate(void)'
1> with
1> [
1> ASeq=boost::archive::detail::known_archive_types::type,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(132) : see reference to
class template instantiation
'boost::archive::detail::export_impl::for_each_archive<ASeq,T>' being
compiled
1> with
1> [
1> ASeq=boost::archive::detail::known_archive_types::type,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(131) : while compiling
class template member function
'boost::archive::detail::export_generator<T,ASeq>::export_generator(void)'
1> with
1> [
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1> include\boost\serialization\export.hpp(177) : see reference to
class template instantiation
'boost::archive::detail::export_generator<T,ASeq>' being compiled
1> with
1> [
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1> include\boost\serialization\export.hpp(176) : while compiling
class template member function 'const
boost::archive::detail::export_generator<T,ASeq>
*boost::archive::detail::export_instance<T,ASeq>::not_abstract::invoke(void)'
1> with
1> [
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1> include\boost\serialization\export.hpp(192) : see reference to
class template instantiation
'boost::archive::detail::export_instance<T,ASeq>::not_abstract' being
compiled
1> with
1> [
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1> include\boost\serialization\export.hpp(211) : see reference to
function template instantiation 'std::pair<_Ty1,_Ty2>
boost::archive::detail::export_instance_invoke<T,ASeq>(void)' being compiled
1> with
1> [
1> _Ty1=const
boost::archive::detail::export_generator<B,boost::archive::detail::known_archive_types::type>
*,
1> _Ty2=const boost::archive::detail::guid_initializer<B> *,
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1> include\boost\serialization\export.hpp(210) : while compiling
class template member function 'std::pair<_Ty1,_Ty2>
boost::archive::detail::export_archives<T,ASeq>::non_empty_archive_list::invoke(void)'
1> with
1> [
1> _Ty1=const
boost::archive::detail::export_generator<B,boost::archive::detail::known_archive_types::type>
*,
1> _Ty2=const boost::archive::detail::guid_initializer<B> *,
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1> include\boost\serialization\export.hpp(225) : see reference to
class template instantiation
'boost::archive::detail::export_archives<T,ASeq>::non_empty_archive_list'
being compiled
1> with
1> [
1> T=B,
1> ASeq=boost::archive::detail::known_archive_types::type
1> ]
1>
c:\users\awk\desktop\work\code\src\tests\scenegraph_regression\_main.cpp(129)
: see reference to function template instantiation 'std::pair<_Ty1,_Ty2>
boost::archive::detail::export_archives_invoke<B,boost::archive::detail::known_archive_types::type>(B
&,boost::archive::detail::known_archive_types::type &)' being compiled
1> with
1> [
1> _Ty1=const
boost::archive::detail::export_generator<B,boost::archive::detail::known_archive_types::type>
*,
1> _Ty2=const boost::archive::detail::guid_initializer<B> *
1> ]
1>include\boost\serialization\access.hpp(109) : error C2664: 'void
B::serialize(boost::archive::polymorphic_iarchive &,const unsigned int)' :
cannot convert parameter 1 from 'boost::archive::text_iarchive' to
'boost::archive::polymorphic_iarchive &'
1> include\boost\serialization\serialization.hpp(81) : see reference
to function template instantiation 'void
boost::serialization::access::serialize<Archive,T>(Archive &,T &,const
unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\serialization\serialization.hpp(140) : see reference
to function template instantiation 'void
boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(164) : see reference
to function template instantiation 'void
boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(157) : while
compiling class template member function 'void
boost::archive::detail::iserializer<Archive,T>::load_object_data(boost::archive::detail::basic_iarchive
&,void *,const unsigned int) const'
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(175) : see reference
to class template instantiation
'boost::archive::detail::iserializer<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(174) : while
compiling class template member function 'const
boost::archive::detail::basic_iserializer
&boost::archive::detail::pointer_iserializer<T,Archive>::get_basic_serializer(void)
const'
1> with
1> [
1> T=B,
1> Archive=boost::archive::text_iarchive
1> ]
1> include\boost\archive\detail\iserializer.hpp(546) : see reference
to class template instantiation
'boost::archive::detail::pointer_iserializer<T,Archive>' being compiled
1> with
1> [
1> T=B,
1> Archive=boost::archive::text_iarchive
1> ]
1> include\boost\serialization\export.hpp(78) : see reference to
function template instantiation 'const
boost::archive::detail::basic_pointer_iserializer
&boost::archive::detail::instantiate_pointer_iserializer<Archive,T>(Archive
*,T *)' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(74) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::i::invoke(void)'
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(105) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>::i' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(89) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::instantiate(void)'
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(116) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::text_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(115) : while compiling
class template member function 'void
boost::archive::detail::export_impl::for_each_archive<ASeq,T>::instantiate(void)'
1> with
1> [
1>
ASeq=boost::mpl::list5<boost::archive::text_iarchive,boost::archive::xml_oarchive,boost::archive::xml_iarchive,boost::archive::polymorphic_oarchive,boost::archive::polymorphic_iarchive>,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(122) : see reference to
class template instantiation
'boost::archive::detail::export_impl::for_each_archive<ASeq,T>' being
compiled
1> with
1> [
1>
ASeq=boost::mpl::list5<boost::archive::text_iarchive,boost::archive::xml_oarchive,boost::archive::xml_iarchive,boost::archive::polymorphic_oarchive,boost::archive::polymorphic_iarchive>,
1> T=B
1> ]
1>include\boost\serialization\access.hpp(109) : error C2664: 'void
B::serialize(boost::archive::polymorphic_iarchive &,const unsigned int)' :
cannot convert parameter 1 from 'boost::archive::xml_oarchive' to
'boost::archive::polymorphic_iarchive &'
1> include\boost\serialization\serialization.hpp(81) : see reference
to function template instantiation 'void
boost::serialization::access::serialize<Archive,T>(Archive &,T &,const
unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\serialization\serialization.hpp(140) : see reference
to function template instantiation 'void
boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(152) : see reference
to function template instantiation 'void
boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(145) : while
compiling class template member function 'void
boost::archive::detail::oserializer<Archive,T>::save_object_data(boost::archive::detail::basic_oarchive
&,const void *) const'
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(163) : see reference
to class template instantiation
'boost::archive::detail::oserializer<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\archive\detail\oserializer.hpp(162) : while
compiling class template member function 'const
boost::archive::detail::basic_oserializer
&boost::archive::detail::pointer_oserializer<T,Archive>::get_basic_serializer(void)
const'
1> with
1> [
1> T=B,
1> Archive=boost::archive::xml_oarchive
1> ]
1> include\boost\archive\detail\oserializer.hpp(515) : see reference
to class template instantiation
'boost::archive::detail::pointer_oserializer<T,Archive>' being compiled
1> with
1> [
1> T=B,
1> Archive=boost::archive::xml_oarchive
1> ]
1> include\boost\serialization\export.hpp(86) : see reference to
function template instantiation 'const
boost::archive::detail::basic_pointer_oserializer
&boost::archive::detail::instantiate_pointer_oserializer<Archive,T>(Archive
*,T *)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(82) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::o::invoke(void)'
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(105) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>::o' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(89) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::instantiate(void)'
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(116) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::xml_oarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(115) : while compiling
class template member function 'void
boost::archive::detail::export_impl::for_each_archive<ASeq,T>::instantiate(void)'
1> with
1> [
1>
ASeq=boost::mpl::list4<boost::archive::xml_oarchive,boost::archive::xml_iarchive,boost::archive::polymorphic_oarchive,boost::archive::polymorphic_iarchive>,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(122) : see reference to
class template instantiation
'boost::archive::detail::export_impl::for_each_archive<ASeq,T>' being
compiled
1> with
1> [
1>
ASeq=boost::mpl::list4<boost::archive::xml_oarchive,boost::archive::xml_iarchive,boost::archive::polymorphic_oarchive,boost::archive::polymorphic_iarchive>,
1> T=B
1> ]
1>include\boost\serialization\access.hpp(109) : error C2664: 'void
B::serialize(boost::archive::polymorphic_iarchive &,const unsigned int)' :
cannot convert parameter 1 from 'boost::archive::xml_iarchive' to
'boost::archive::polymorphic_iarchive &'
1> include\boost\serialization\serialization.hpp(81) : see reference
to function template instantiation 'void
boost::serialization::access::serialize<Archive,T>(Archive &,T &,const
unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\serialization\serialization.hpp(140) : see reference
to function template instantiation 'void
boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(164) : see reference
to function template instantiation 'void
boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned
int)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(157) : while
compiling class template member function 'void
boost::archive::detail::iserializer<Archive,T>::load_object_data(boost::archive::detail::basic_iarchive
&,void *,const unsigned int) const'
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(175) : see reference
to class template instantiation
'boost::archive::detail::iserializer<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\archive\detail\iserializer.hpp(174) : while
compiling class template member function 'const
boost::archive::detail::basic_iserializer
&boost::archive::detail::pointer_iserializer<T,Archive>::get_basic_serializer(void)
const'
1> with
1> [
1> T=B,
1> Archive=boost::archive::xml_iarchive
1> ]
1> include\boost\archive\detail\iserializer.hpp(546) : see reference
to class template instantiation
'boost::archive::detail::pointer_iserializer<T,Archive>' being compiled
1> with
1> [
1> T=B,
1> Archive=boost::archive::xml_iarchive
1> ]
1> include\boost\serialization\export.hpp(78) : see reference to
function template instantiation 'const
boost::archive::detail::basic_pointer_iserializer
&boost::archive::detail::instantiate_pointer_iserializer<Archive,T>(Archive
*,T *)' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(74) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::i::invoke(void)'
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(105) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>::i' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(89) : while compiling class
template member function 'void
boost::archive::detail::export_impl::archive<Archive,T>::instantiate(void)'
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(116) : see reference to
class template instantiation
'boost::archive::detail::export_impl::archive<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::xml_iarchive,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(115) : while compiling
class template member function 'void
boost::archive::detail::export_impl::for_each_archive<ASeq,T>::instantiate(void)'
1> with
1> [
1>
ASeq=boost::mpl::list3<boost::archive::xml_iarchive,boost::archive::polymorphic_oarchive,boost::archive::polymorphic_iarchive>,
1> T=B
1> ]
1> include\boost\serialization\export.hpp(122) : see reference to
class template instantiation
'boost::archive::detail::export_impl::for_each_archive<ASeq,T>' being
compiled
1> with
1> [
1>
ASeq=boost::mpl::list3<boost::archive::xml_iarchive,boost::archive::polymorphic_oarchive,boost::archive::polymorphic_iarchive>,
1> T=B
1> ]
----- Original Message -----
From: "Robert Ramey" <ramey_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.user
Sent: Tuesday, November 07, 2006 2:42 AM
Subject: Re: Serialization with polymorphic_*_archiveandBOOST_CLASS_EXPORT
> Anders Wang Kristensen wrote:
>> Hi,
>>
>> I'm having trouble serializing through the a pointer to the base as
>> shown below.
>> If I manually register class B with template register_type<B>() it
>> works, but I
>> would rather use the BOOST_CLASS_EXPORT macros since that is more
>> convenient.
>>
>> Unfortunately BOOST_CLASS_EXPORT assumes you are using the templated
>> version of serialize, and not polymorphic_iarchive/oarchive, that I'm
>> using.
>
> I don't think that's true. Maybe you mean it assums you are using
> member serialize functions - but that won't be true either.
>
> Basically I think your example should function. Where does it fail?
> Does it throw and exception? where? does the assert fail?, etc.,etc.
> Also what compiler, os, version of boost etc.?
>
> Though its beside the point, I would also make your example more portable
> wit the fillowing
> changes:
>
> ...
> struct A {
> template<class Archive>
> void serialize(Archive & ar, const unsigned int file_version);
> ...
> };
> template<class Archive>
> void A::serialize(Archive & ar, const unsigned int file_version){
> ar & BOOST_SERIALIZATION_NVP(data);
> }
>
> struct B : public A {
> template<class Archive>
> void serialize(Archive & ar, const unsigned int file_version);
> ...
> };
>
> template<class Archive>
> void B::serialize(Archive & ar, const unsigned int file_version){
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
> ar & BOOST_SERIALIZATION_NVP(foo);
> }
>
> BOOST_CLASS_EXPORT(B)
>
> int main(int argc, const char* argv[]){
> boost::shared_ptr<A> a(new B);
> boost::shared_ptr<A> a1;
> std::stringstream ss;
> {
> boost::archive::polymorphic_text_oarchive oa(ss);
> //oa.template register_type<B>();
> oa << BOOST_SERIALIZATION_NVP(a);
> }
> try{
> boost::archive::polymorphic_text_iarchive ia(ss);
> //ia.template register_type<B>();
> ia >> BOOST_SERIALIZATION_NVP(a1);
> }
> catch(...){
> ...
> }
> B* x = dynamic_cast<B*>(a.get());
> B* y = dynamic_cast<B*>(b.get());
>
> assert(*x == *y);
> return 0;
> }
----- Original Message -----
From: "Robert Ramey" <ramey_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.user
Sent: Tuesday, November 07, 2006 2:42 AM
Subject: Re: Serialization with polymorphic_*_archiveandBOOST_CLASS_EXPORT
> Anders Wang Kristensen wrote:
>> Hi,
>>
>> I'm having trouble serializing through the a pointer to the base as
>> shown below.
>> If I manually register class B with template register_type<B>() it
>> works, but I
>> would rather use the BOOST_CLASS_EXPORT macros since that is more
>> convenient.
>>
>> Unfortunately BOOST_CLASS_EXPORT assumes you are using the templated
>> version of serialize, and not polymorphic_iarchive/oarchive, that I'm
>> using.
>
> I don't think that's true. Maybe you mean it assums you are using
> member serialize functions - but that won't be true either.
>
> Basically I think your example should function. Where does it fail?
> Does it throw and exception? where? does the assert fail?, etc.,etc.
> Also what compiler, os, version of boost etc.?
>
> Though its beside the point, I would also make your example more portable
> wit the fillowing
> changes:
>
> ...
> struct A {
> template<class Archive>
> void serialize(Archive & ar, const unsigned int file_version);
> ...
> };
> template<class Archive>
> void A::serialize(Archive & ar, const unsigned int file_version){
> ar & BOOST_SERIALIZATION_NVP(data);
> }
>
> struct B : public A {
> template<class Archive>
> void serialize(Archive & ar, const unsigned int file_version);
> ...
> };
>
> template<class Archive>
> void B::serialize(Archive & ar, const unsigned int file_version){
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
> ar & BOOST_SERIALIZATION_NVP(foo);
> }
>
> BOOST_CLASS_EXPORT(B)
>
> int main(int argc, const char* argv[]){
> boost::shared_ptr<A> a(new B);
> boost::shared_ptr<A> a1;
> std::stringstream ss;
> {
> boost::archive::polymorphic_text_oarchive oa(ss);
> //oa.template register_type<B>();
> oa << BOOST_SERIALIZATION_NVP(a);
> }
> try{
> boost::archive::polymorphic_text_iarchive ia(ss);
> //ia.template register_type<B>();
> ia >> BOOST_SERIALIZATION_NVP(a1);
> }
> catch(...){
> ...
> }
> B* x = dynamic_cast<B*>(a.get());
> B* y = dynamic_cast<B*>(b.get());
>
> assert(*x == *y);
> return 0;
> }
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