|
Boost Users : |
From: David Parks (davidp_at_[hidden])
Date: 2005-12-03 22:56:56
I'm having a newbie issue with serialization on a derived class with a
virtual function. I'm using the 1.33.0 build on VS 7.1.
I've shrunken my code to a micro-version of what I tried to do. Here I
have two classes, A and B, where B is a subclass of A. They share a
virtual function (ie B overrides dumpFunc in A). I've registered B with
BOOST_CLASS_EXPORT(B). I've turned on RTTI in VS 7.1 (/GR or
whatever). Still, I get a run time assert error in the boost library
telling me that the derived/base relationship wasn't registered. Here's
the code. I'll try to spell out the error below.
#include <string>
#include <fstream>
#include <boost/archive/tmpdir.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/vector.hpp>
class A;
class B;
class A
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & m_className;
};
std::string m_className;
public:
A()
{
m_className = "ClassA\n";
};
virtual void dumpFunc() {};
};
class B : public A
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & m_classNameB;
};
std::string m_classNameB;
public:
B()
{
m_classNameB = "ClassB\n";
};
virtual void dumpFunc() {};
};
BOOST_CLASS_EXPORT(B)
void main()
{
std::vector<A *> vecA;
B *b=new B();
vecA.push_back(b);
std::ofstream ofs("saveFile.sav");
boost::archive::text_oarchive oa(ofs);
oa & vecA;
delete b;
}
The following is a stack trace of where it hits the assert. The key
thing to note is that save_pointer_type bails out after deciding that
class B was not registered. I'm hoping that this is a rookie error but
I just can't see it. Thanks.
kernel32.dll!7c81eb33() kernel32.dll!7c81eb33()
junkProject.exe!_CxxThrowException(void * pExceptionObject=0x0012de10,
const _s__ThrowInfo * pThrowInfo=0x004f8400) + 0x39 C++
>
junkProject.exe!boost::throw_exception<boost::archive::archive_exception>(const
boost::archive::archive_exception & e={...}) Line 40 C++
junkProject.exe!boost::archive::detail::save_pointer_type<boost::archive::text_oarchive,A
*>::polymorphic<A>::save(boost::archive::text_oarchive & ar={...}, const
A & t={...}, const boost::archive::detail::basic_pointer_oserializer *
bpos_ptr=0x00504544) Line 410 + 0x34 C++
junkProject.exe!boost::archive::detail::save_pointer_type<boost::archive::text_oarchive,A
*>::save<A>(boost::archive::text_oarchive & ar={...}, const A & t={...},
const boost::archive::detail::basic_pointer_oserializer *
bpos_ptr=0x00504544) Line 438 + 0x11 C++
junkProject.exe!boost::archive::detail::save_pointer_type<boost::archive::text_oarchive,A
*>::invoke(boost::archive::text_oarchive & ar={...}, A * const
t=0x00323bb0) Line 466 + 0x11 C++
junkProject.exe!boost::archive::save<boost::archive::text_oarchive,A
*>(boost::archive::text_oarchive & ar={...}, A * const & t=0x00323bb0)
Line 535 + 0xf C++
junkProject.exe!boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<A
* const>() Line 78 + 0x15 C++
junkProject.exe!boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<<<A
* const>() Line 86 C++
junkProject.exe!boost::serialization::nvp<A *
const>::save<boost::archive::text_oarchive>() Line 78 C++
junkProject.exe!boost::serialization::access::member_save<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> const >() Line 94 C++
junkProject.exe!boost::serialization::detail::member_saver<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >::invoke(boost::archive::text_oarchive & ar={...}, const
boost::serialization::nvp<A * const> & t={...}, const unsigned int
file_version=0) Line 43 + 0x11 C++
junkProject.exe!boost::serialization::split_member<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >(boost::archive::text_oarchive & ar={...},
boost::serialization::nvp<A * const> & t={...}, const unsigned int
file_version=0) Line 69 + 0x11 C++
junkProject.exe!boost::serialization::nvp<A *
const>::serialize<boost::archive::text_oarchive>() Line 87 + 0x34 C++
junkProject.exe!boost::serialization::access::serialize<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >() Line 110 C++
junkProject.exe!boost::serialization::serialize<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >(boost::archive::text_oarchive & ar={...},
boost::serialization::nvp<A * const> & t={...}, const unsigned int
file_version=0) Line 81 + 0x11 C++
junkProject.exe!boost::serialization::serialize_adl<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >(boost::archive::text_oarchive & ar={...},
boost::serialization::nvp<A * const> & t={...}, const unsigned int
file_version=0) Line 140 + 0x18 C++
junkProject.exe!boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >::save_only::invoke(boost::archive::text_oarchive & ar={...},
const boost::serialization::nvp<A * const> & t={...}) Line 256 + 0xf
C++
junkProject.exe!boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >::invoke(boost::archive::text_oarchive & ar={...}, const
boost::serialization::nvp<A * const> & t={...}) Line 321 + 0xd C++
junkProject.exe!boost::archive::save<boost::archive::text_oarchive,boost::serialization::nvp<A
* const> >(boost::archive::text_oarchive & ar={...}, const
boost::serialization::nvp<A * const> & t={...}) Line 535 + 0xd C++
junkProject.exe!boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<boost::serialization::nvp<A
* const> const >() Line 78 + 0x15 C++
junkProject.exe!boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<<<boost::serialization::nvp<A
* const> const >() Line 86 C++
junkProject.exe!boost::serialization::stl::save_collection<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> > >(boost::archive::text_oarchive & ar={...},
const std::vector<A *,std::allocator<A *> > & s={...}) Line 44 C++
junkProject.exe!boost::serialization::save<boost::archive::text_oarchive,A
*,std::allocator<A *> >(boost::archive::text_oarchive & ar={...}, const
std::vector<A *,std::allocator<A *> > & t={...}, const unsigned int
__formal=0) Line 49 + 0xd C++
junkProject.exe!boost::serialization::free_saver<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> > >::invoke(boost::archive::text_oarchive &
ar={...}, const std::vector<A *,std::allocator<A *> > & t={...}, const
unsigned int file_version=0) Line 45 + 0x18 C++
junkProject.exe!boost::serialization::split_free<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> > >(boost::archive::text_oarchive & ar={...},
std::vector<A *,std::allocator<A *> > & t={...}, const unsigned int
file_version=0) Line 74 + 0x11 C++
junkProject.exe!boost::serialization::serialize<boost::archive::text_oarchive,A
*,std::allocator<A *> >(boost::archive::text_oarchive & ar={...},
std::vector<A *,std::allocator<A *> > & t={...}, const unsigned int
file_version=0) Line 76 + 0x11 C++
junkProject.exe!boost::serialization::serialize_adl<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> > >(boost::archive::text_oarchive & ar={...},
std::vector<A *,std::allocator<A *> > & t={...}, const unsigned int
file_version=0) Line 140 + 0x18 C++
junkProject.exe!boost::archive::detail::oserializer<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> >
>::save_object_data(boost::archive::detail::basic_oarchive & ar={...},
const void * x=0x0012febc) Line 151 + 0x2b C++
junkProject.exe!boost::archive::detail::basic_oarchive_impl::save_object(boost::archive::detail::basic_oarchive
& ar={...}, const void * t=0x0012febc, const
boost::archive::detail::basic_oserializer & bos={...}) Line 271 C++
junkProject.exe!boost::archive::detail::basic_oarchive::save_object(const
void * x=0x0012febc, const boost::archive::detail::basic_oserializer &
bos={...}) Line 412 C++
junkProject.exe!boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> >
>::save_standard::invoke(boost::archive::text_oarchive & ar={...},
const std::vector<A *,std::allocator<A *> > & t={...}) Line 264 C++
junkProject.exe!boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> > >::invoke(boost::archive::text_oarchive &
ar={...}, const std::vector<A *,std::allocator<A *> > & t={...}) Line
321 + 0xd C++
junkProject.exe!boost::archive::save<boost::archive::text_oarchive,std::vector<A
*,std::allocator<A *> > >(boost::archive::text_oarchive & ar={...},
const std::vector<A *,std::allocator<A *> > & t={...}) Line 535 +
0xd C++
junkProject.exe!boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<A
*,std::allocator<A *> > const >() Line 78 + 0x15 C++
junkProject.exe!boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<<<std::vector<A
*,std::allocator<A *> > const >() Line 86 C++
junkProject.exe!boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<std::vector<A
*,std::allocator<A *> > >(std::vector<A *,std::allocator<A *> > &
t={...}) Line 97 C++
junkProject.exe!main() Line 65 C++
junkProject.exe!mainCRTStartup() Line 259 + 0x19 C
kernel32.dll!7c816d4f() ntdll.dll!7c915b4f()
kernel32.dll!7c8399f3()
- David
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