且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

升压反序列化派生类的基类指针

更新时间:2023-02-15 15:10:42

您可能正在使用您的库时得到一个的 input_stream_error 的在您的演示和 unregistered_class 的异常。这是由升压方式造成正在注册的类,在你的情况下,自动完成。

You're probably getting an input_stream_error in your demo and unregistered_class exception when using your library. This is caused by the way boost is registering the classes, in your case, automatically.

看来,自动注册过程会很困惑,当你序列化派生类对象和反序列化到它的基地,尽管使用了BOOST_CLASS_EXPORT *宏。

It appears that the automatic registration process gets confused when you serialize a derived object and deserialize to its base, despite the use of the BOOST_CLASS_EXPORT* macros.

不过,可以明确的注册类您在存档执行任何I / O操作前:

However, you can register the classes explicitly before you perform any i/o operation on the archive:

// ...
boost::archive::xml_iarchive archive(stream);
// register the class(es) with the archive
archive.template register_type<command>();
archive >> BOOST_SERIALIZATION_NVP(t);
// ...

序列化时使用登记顺序相同。这使得出口宏多余的。

Use the same order of registration when serializing. This makes the export macros superfluous.