I already sent a message on this topic a few weeks ago, however, my problem
has a changed a bit so I decided to post a new message.
I've been trying to get Boost serialization working for dynamically loaded
shared libraries. Here's my basic structure simplified:
1. base.hpp - includes an abstract base class called base
2. derived.hpp - includes a derived class from base. includes base.hpp.
3. derived.cpp - includes code for derived class and for dynamically loading
it
4. main.cpp - includes base.hpp but NOT derived.hpp. dynamically loads
instantiates a base * which points to a derived object from derived.so
Now in main I want to be able to serialize my pointer to the loaded derived
class:
base *obj = create_func(); //obj now points to a derived object
obj->test(); //when test is run it correctly outputs the message from
derived.cpp
const base* const to_serialize = obj;
std::ofstream ofs("filename");
boost::archive::text_oarchive oa(ofs);
try
{
oa << (to_serialize);
}
catch(exception &e)
{
cout << "Exception: " << e.what() << "\n";
}
It compiles fine and I got past the "unregisterd class" problem, but now
when I try to serialize the pointer an exception is caught:
"Unregistered void cast"
This appears to be a problem with registering the derived pointer type from
the base type when dynamically loaded from a shared library.
However, I do register the derived-base relationship as suggested in the
documentation. The serialize method in derived.hpp is as follows:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar.template register_type(static_cast