On 08/18/2010 06:42 PM, Robert Ramey wrote:
I went back and looked at your example. You're on the wrong track here.
Thank you very much!
First, classes to be serialized should be not dependent in anyway upon any archive class. So use:
Ouch. The reason why I wanted polymorphic archives was to be able to have a non-template serialize() method so that it may be implemented and compiled once for all in the .cpp file.
Test the above to verify that it works according to your taste.
I still have a different behavior when serializing through polymorphic_test_oarchive.
Now use a "templated typedef" to generate the polymorphic version:
#include
#include #include typedef boost::archive::detail::polymorphic_oarchive_route< test_oarchive
polymorphic_test_oarchive;
// required by export BOOST_SERIALIZATION_REGISTER_ARCHIVE( test_oarchive )
or something like this. Now you should have test_oarchive and polymorphic_test_oarchive
That's what I'm doing. So now 'unit' only has a template serialize method, but I still
int main() { unit u(42);
{ std::cout << "template:" << std::endl; test_oarchive ar(std::cout); ar << BOOST_SERIALIZATION_NVP(u); std::cout << std::endl; }
{ std::cout << "polymorphic:" << std::endl; polymorphic_test_oarchive ar(std::cout); ar << BOOST_SERIALIZATION_NVP(u); std::cout << std::endl; } }
Which outputs:
template:
42 polymorphic: 42
Code is attached. -- Maxime