I compiled, linked and executed this exact program on my VC 7.1 setup.
I had no problems of any kind
Robert Ramey
wrote in message
news:OF92B08D23.E5C8FCC6-ON8525713E.0055B2DA-8525713E.0056B680@jpmchase.com...
Thanks for the help. The new code works.
For my application, I would like to use BOOST_CLASS_EXPORT_GUID to simplify
the registration process. Changing the demo code to use EXPORT causes it to
core dump. Perhaps I'm not using correctly... Again, help would be
appreciated.
Wayne Liu
#0 0x004a2575 in boost::archive::detail::basic_iarchive_impl::load_preamble
()
from
/cbb/public/wayne/build/lib/libboost_serialization-gcc-1_33_1.so.1.33.1
#1 0x004a30b9 in boost::archive::detail::basic_iarchive_impl::load_pointer
()
from
/cbb/public/wayne/build/lib/libboost_serialization-gcc-1_33_1.so.1.33.1
#2 0x004a2934 in boost::archive::detail::basic_iarchive::load_pointer ()
from
/cbb/public/wayne/build/lib/libboost_serialization-gcc-1_33_1.so.1.33.1
#3 0x0804d989 in
boost::archive::detail::load_pointer_type::invoke (ar=@0xbfff7fd0, t=@0xbfff800c)
at
/cbb/public/wayne/build/include/boost-1_33_1/boost/archive/detail/iserializer.hpp:486
#4 0x0804d8f6 in load
(ar=@0xbfff7fd0, t=@0xbfff800c)
at
/cbb/public/wayne/build/include/boost-1_33_1/boost/archive/detail/iserializer.hpp:572
#5 0x0804d80b in
boost::archive::basic_text_iarchiveboost::archive::text_iarchive::load_override
(this=0xbfff7fd0, t=@0xbfff800c)
at
/cbb/public/wayne/build/include/boost-1_33_1/boost/archive/basic_text_iarchive.hpp:64
#6 0x0804d718 in
boost::archive::text_iarchive_implboost::archive::text_iarchive::load_override
(this=0xbfff7fd0, t=@0xbfff800c)
at
/cbb/public/wayne/build/include/boost-1_33_1/boost/archive/text_iarchive.hpp:64
#7 0x0804d65d in operator>> (this=0xbfff7fd0, t=@0xbfff800c)
at
/cbb/public/wayne/build/include/boost-1_33_1/boost/archive/detail/interface_iarchive.hpp:76
#8 0x0804c807 in restore (ss=@0xbfff8070) at test/d3.cpp:138
#9 0x0804cf69 in main (argc=1, argv=0xbfff8274) at test/d3.cpp:180
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// demo.cpp
//
// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include
#include
#include
#include
#include
#include
/////////////////////////////////////////////////////////////
// One bus stop
//
// illustrates serialization of serializable members
//
class bus_stop
{
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const bus_stop &gp);
virtual std::string description() const = 0;
int latitude;
int longitude;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & latitude;
ar & longitude;
}
protected:
bus_stop(const int & _lat, const int & _long) :
latitude(_lat), longitude(_long)
{}
public:
bus_stop(){}
virtual ~bus_stop(){}
};
BOOST_IS_ABSTRACT(bus_stop)
BOOST_CLASS_EXPORT_GUID(bus_stop, "bus_stop")
std::ostream & operator<<(std::ostream &os, const bus_stop &bs)
{
return os << bs.latitude << bs.longitude << ' ' << bs.description();
}
/////////////////////////////////////////////////////////////
// Several kinds of bus stops
//
// illustrates serialization of derived types
//
class bus_stop_corner : public bus_stop
{
friend class boost::serialization::access;
std::string street1;
std::string street2;
virtual std::string description() const
{
return street1 + " and " + street2;
}
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
// save/load base class information
ar & boost::serialization::base_object(*this);
ar & street1 & street2;
}
public:
bus_stop_corner(){}
bus_stop_corner(const int & _lat, const int & _long,
const std::string & _s1, const std::string & _s2
) :
bus_stop(_lat, _long), street1(_s1), street2(_s2)
{
}
};
BOOST_CLASS_EXPORT_GUID(bus_stop_corner, "bus_stop_corner")
class bus_stop_destination : public bus_stop
{
friend class boost::serialization::access;
std::string name;
virtual std::string description() const
{
return name;
}
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & boost::serialization::base_object(*this) & name;
}
public:
bus_stop_destination(){}
bus_stop_destination(
const int & _lat, const int & _long, const std::string & _name
) :
bus_stop(_lat, _long), name(_name)
{
}
};
BOOST_CLASS_EXPORT_GUID(bus_stop_destination, "bus_stop_destination")
void save(const bus_stop * const s, std::stringstream &ss) /* NOTE extra
const here !! */
{
std::cout << "original";
std::cout << *s;
boost::archive::text_oarchive oa(ss);
//oa.register_type(static_cast(NULL));
//oa.register_type(static_cast(NULL));
oa << s;
}
void
restore( std::stringstream &ss)
{
bus_stop *s;
boost::archive::text_iarchive ia(ss);
//ia.register_type(static_cast(NULL));
//ia.register_type(static_cast(NULL));
ia >> s;
std::cout << "restored";
std::cout << *s;
}
int main(int argc, char *argv[])
{
// fill in the data
// make a few stops
bus_stop *bs0 = new bus_stop_corner(
34,
134,
"24th Street", "10th Avenue"
);
bus_stop *bs1 = new bus_stop_corner(
35,
133,
"State street", "Cathedral Vista Lane"
);
bus_stop *bs2 = new bus_stop_destination(
35,
133,
"White House"
);
bus_stop *bs3 = new bus_stop_destination(
35,
133,
"Lincoln Memorial"
);
{
std::stringstream ss;
// display the complete schedule
save(bs0,ss);
restore(ss);
}
{
std::stringstream ss;
// display the complete schedule
save(bs1,ss);
restore(ss);
}
{
std::stringstream ss;
// display the complete schedule
save(bs2,ss);
restore(ss);
}
{
std::stringstream ss;
// display the complete schedule
save(bs3,ss);
restore(ss);
}
return 0;
}
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users