
Hello, I cannot really get the serializations to work for hash_maps. Using maps, lists and vectors everything works just fine. Using the sample code pasted below (using a hash_map) gives the following compilation-errors: /usr/include/boost/serialization/access.hpp: In static member function `static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>, std::equal_to<long int>, std::allocator<long int> >]': /usr/include/boost/serialization/serialization.hpp:78: instantiated from `void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>, std::equal_to<long int>, std::allocator<long int> >]' /usr/include/boost/serialization/serialization.hpp:121: instantiated from `void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>, std::equal_to<long int>, std::allocator<long int> >]' /usr/include/boost/archive/detail/oserializer.hpp:148: instantiated from `void boost::archive::detail::oserializer<Archive, T>::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::text_oarchive, T = __gnu_cxx::hash_map<long int, long int, __gnu_cxx::hash<long int>, std::equal_to<long int>, std::allocator<long int> >]' /usr/include/boost/archive/detail/oserializer.hpp:243: instantiated from here /usr/include/boost/serialization/access.hpp:106: error: `serialize' undeclared (first use this function) /usr/include/boost/serialization/access.hpp:106: error: (Each undeclared identifier is reported only once for each function it appears in.) Changing the created class to "busmap" (based on std::map) everything works just fine! (The ONLY difference between the classes is the container-definition) System specs: Linux kernel version 2.4.26 g++ (GCC) 3.3.2 20031218 boost-1.32 Sample code compiled with: g++ -o test test.cpp -lboost_serialization-gcc-mt ================================================== #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/hash_map.hpp> #include <boost/serialization/map.hpp> #include <ext/hash_map> #include <map> class busmap { friend class boost::serialization::access; std::map<long,long> bus_serial_map; // Imaginary bus-serial-number to bus number lookup-table; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & bus_serial_map; } public: busmap(){} }; class bushashmap { friend class boost::serialization::access; __gnu_cxx::hash_map<long,long> bus_serial_map; // Imaginary bus-serial-number to bus number lookup-table; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & bus_serial_map; } public: bushashmap(){} }; int main() { // create and open a character archive for output std::ofstream ofs("filename"); boost::archive::text_oarchive oa(ofs); // create class instance const bushashmap myBusMap; // write class instance to archive oa << myBusMap; // close archive ofs.close(); // ... some time later restore the class instance to its orginal state // create and open an archive for input std::ifstream ifs("filename", std::ios::binary); boost::archive::text_iarchive ia(ifs); // read class state from archive busmap myNewBusMap; ia >> myNewBusMap; // close archive ifs.close(); return 0; } ======================================= Bug or my fault?? Can anyone help? Best regards Peter