Serialization of STL containers?

I am unable to serialize STL containers. Here's an example, with error message foo.cpp: #include <iostream> #include <fstream> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/serialization/list.hpp> #include <boost/archive/tmpdir.hpp> class bus_route { friend class boost::serialization::access; std::list<int> stops; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & stops; } public: bus_route(){} }; main() { std::ofstream ofs("removeme"); boost::archive::text_oarchive oa(ofs); bus_route a; oa << a; } ==== $ gcc -o foo foo.cpp /usr/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = bus_route]': /usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = bus_route, Archive = boost::archive::text_oarchive]' /usr/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = bus_route, Archive = boost::archive::text_oarchive]' foo.cpp:29: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:567: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>' Any idea what I'm doing wrong?

Wow, it worked! Is that in the documentation? I must have missed it. Thanks, Joseph On Dec 13, 2007 10:00 PM, Mahesh Venkitachalam <mkvenkit.vc@gmail.com> wrote:
On Dec 14, 2007 8:13 AM, Joseph Turian <turian@gmail.com> wrote:
main() { std::ofstream ofs("removeme"); boost::archive::text_oarchive oa(ofs); bus_route a; oa << a; }
The object has to be const, I think - can you try:
const bus_route& b = a; oa << b;
Mahesh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Academic: http://www-etud.iro.umontreal.ca/~turian/ Business: http://www.metaoptimize.com/

On Dec 14, 2007 9:18 AM, Joseph Turian <turian@gmail.com> wrote:
Wow, it worked! Is that in the documentation? I must have missed it.
Thanks, Joseph
In the example below, they use a const. I made the same mistake..;-) http://www.boost.org/libs/serialization/doc/index.html Mahesh
participants (2)
-
Joseph Turian
-
Mahesh Venkitachalam