Boost logo

Boost Users :

From: Joseph Turian (turian_at_[hidden])
Date: 2006-01-17 23:27:29


> b) use BOOST_STRONG_TYPE to make an integer type that is tracked.

Okay. The code snippet you gave me worked great.

However, I am now experiencing what I hope is the final problem.
Basically, I have a recursive data structure A, which contains
pointers of type boost::smart_pointer<A>.

Could you please show me how to get the follow code snippet to work?

I should say that I'm really appreciative for all your help.

--------

#include <iostream>
#include <fstream>

#include <boost/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/tracking.hpp>
#include <boost/strong_typedef.hpp>

class A;
BOOST_STRONG_TYPEDEF(boost::shared_ptr<A>, Aptr)
class A {
public:
        friend class boost::serialization::access;
        template<class Archive> void serialize(Archive& ar, const
unsigned int version) {
                ar & aptr;
        }
private:
        Aptr aptr;
};

template <class Archive>
void serialize(Archive &ar, Aptr &aptr, const unsigned int version) {
        ar & static_cast<boost::shared_ptr<A> >(aptr);
}

int main() {
        std::ofstream ofs("archive");
        boost::archive::text_oarchive oa(ofs);

        A a;
        oa << a;

        Aptr aptr;
        oa << aptr;

        return 0;
}

--------

Thanks!

   Joseph

--
http://www.cs.nyu.edu/~turian/

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