Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-01-20 21:26:51


> Well, I see how your example compiles in the case of RAW cyclic
> pointers. However, I cannot use raw pointers, and I don't know how to
> get it to compile with cyclic smart pointers (specifically,
> boost::shared_ptr). Was there something that I missed?

Just use a smart pointer instead of a raw pointer. The following
compiles as expected.

#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/shared_ptr.hpp>
class A {
public:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(
        Archive& ar,
        const unsigned int version
    ) {
        ar & aptr;
    }
private:
    boost::shared_ptr<A> aptr;
};
int main() {
    std::ofstream ofs("archive");
    boost::archive::text_oarchive oa(ofs);
    const A a;
    oa << a;
    return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net