Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-09-17 14:01:58


Neal Becker wrote:
> I noticed that if I use both BOOST_CLASS_EXPORT and register_type it
> causes
> an error. Here is an example:
snip ...

> template<class Archive>
> void save (Archive & ar, const unsigned int version) const {
> ar.register_type (static_cast<derived*>(NULL)); //comment/uncomment
> this line
> std::cout << b->min << ' ' << b->max << '\n';
> ar << BOOST_SERIALIZATION_NVP(b);
> }
>
> template<class Archive>
> void load (Archive & ar, const unsigned int version) {
    ar.register_type (static_cast<derived*>(NULL)); //add this line
> base* b = NULL;
> ar >> BOOST_SERIALIZATION_NVP(b);
> std::cout << b->min << ' ' << b->max << '\n';
> }
>
> BOOST_SERIALIZATION_SPLIT_MEMBER()
> };
>

> If ar.register_type is there, you get unregistered exception.

registration must occur symetrically in both save and load.

an easier way to guarentee this would be to use:

template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
    ar.register_type (static_cast<derived*>(NULL));
    ar & BOOST_SERIALIZATION_NVP(b);
    std::cout << b->min << ' ' << b->max << '\n';
}

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk