boost::shared_ptr and serialization

Hi, I am trapped in an assertion from boost::serialization and maybe someone here has an idea how to solve this. I am using Visual Studio 2008 with Boost 1.49.0 having a simple class in a shared library like : class CTest : public ICTest { friend class boost::serialization::access; template<class Archive> void serialize( Archive & ar, const unsigned int version) { ar & boost::serialization::base_object<ICTest>(*this); ar & i; }; public : CTest::CTest():i(0){}; void setI( int _i){ i = _i;}; int getI( void){ return i;}; int i; }; and an interface class like : class ICTest { friend class boost::serialization::access; template<class Archive> void serialize( Archive & ar, const unsigned int version){}; public : virtual ~ICTest(){}; virtual void setI( int _i) = 0; virtual int getI( void) = 0; }; For the CTest class is not exported and not accessible directly from out of the shared lib, an interface is provided : MY_DLL_EXPORT_MACRO ICTest* CreateCTestClassInstance( void) { return new CTest(); } typedef boost::shared_ptr<ICTest> pICTest; Instantiating the interface in my program and using CTest class instance: pICTest p1( CreateCTestClassInstance()); p1->setI( 1); works fine, so far so good. A Problem occures when I try to serialize CTest class like : { std::ofstream ofs( fileNameTXT); boost::archive::text_oarchive ar( ofs); ar & p1; // causes an assertion } This results in an assertion (->BOOST_ASSERT(false);) in basic_serializer_map.cpp in line 102. It seems to me, there is a problem with finding the derived class in the basic_serializer_map. Instantiation of CTest class directly terminates with no error, which means, the serialization basically works correctly. Does anyone have an idea how to serialize an interface class correctly ? Peter

Klaus - Peter Weber wrote:
Hi, For the CTest class is not exported and not accessible directly from out of the shared lib, an interface is provided :
MY_DLL_EXPORT_MACRO ICTest* CreateCTestClassInstance( void) { return new CTest(); } typedef boost::shared_ptr<ICTest> pICTest;
Instantiating the interface in my program and using CTest class instance:
pICTest p1( CreateCTestClassInstance()); p1->setI( 1);
works fine, so far so good. A Problem occures when I try to serialize CTest class like :
Look at the documentation under serialization of pointers, export, etc. look at the sample applications demo_plugins and others. This should help Robert Ramey
participants (2)
-
Klaus - Peter Weber
-
Robert Ramey