Re: boost serialization polymorphic
От: uzhas Ниоткуда  
Дата: 20.04.11 06:31
Оценка: 3 (1)
Здравствуйте, Аноним, Вы писали:

А>Ищу рабочий пример сериализации полиморфных структур с помощью буста.

А>Данный код не работает: сериализуется только базовый класс. Где ошибка?
я в бусте ничего не понимаю, но немного почитал документацию
http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/serialization.html#derivedpointers

It turns out that the kind of object serialized depends upon whether the base class (base in this case) is polymophic or not. If base is not polymorphic, that is if it has no virtual functions, then an object of the type base will be serialized. Information in any derived classes will be lost. If this is what is desired (it usually isn't) then no other effort is required.

If the base class is polymorphic, an object of the most derived type (derived_one or derived_two in this case) will be serialized. The question of which type of object is to be serialized is (almost) automatically handled by the library.

попробуйте добавить виртуальный деструктор в базу
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.