Index: shared_ptr_helper.hpp =================================================================== --- shared_ptr_helper.hpp (リビジョン 53717) +++ shared_ptr_helper.hpp (作業コピー) @@ -126,10 +126,36 @@ if(it == m_pointers->end()){ s.reset(r); - m_pointers->insert(collection_type::value_type(od,s)); + // make shared_ptr. + // data member pn of shared_ptr sp shared with s, + // but data member px of shared_ptr sp is od. + shared_ptr sp(s, const_cast(od)); // aliasing + // insert shared_ptr of the most derived object into m_pointers. + m_pointers->insert(collection_type::value_type(od,sp)); } else{ - s = static_pointer_cast((*it).second); + const boost::serialization::extended_type_info * true_type + = boost::serialization::type_info_implementation::type + ::get_const_instance().get_derived_extended_type_info(*r); + if(NULL == true_type) + boost::serialization::throw_exception( + boost::archive::archive_exception( + boost::archive::archive_exception::unregistered_class + ) + ); + const boost::serialization::extended_type_info * this_type + = & boost::serialization::type_info_implementation::type + ::get_const_instance(); + // get this type pointer from pointer to the most derived object. + void * vp = void_upcast( + *true_type, + *this_type, + (*it).second.get() + ); + // make and set shared_ptr. + // data member pn of shared_ptr s shared with (*it).second, + // but data member px of shared_ptr s is vp. + s = shared_ptr((*it).second, static_cast(vp)); // aliasing } } void append(const boost_132::shared_ptr & t){