I want to serialize a hash map to a file and de-serialize it later on.
#include <boost/serialization/hash_map.hpp>
#include <boost/filesystem/fstream.hpp>
#include <hash_map>
class A: virtual public B {
public:
friend class boost::serialization::access;
stdext::hash_map<std::string, myClass> myClassHashTable;
template <class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & myClassHashTable;
}
};
void A::serializedToDisk()
{
boost::filesystem::path finalPath(SOME_CONSTANT);
// code to create boost::filesystem::ifstream ofs object
boost::archive::text_oarchive oa(ofs);
oa << myClassHashTable;
}
void A::restoreFromDisk()
{
boost::filesystem::path finalPath(SOME_CONSTANT);
// code to create boost::filesystem::ifstream ifs object
boost::archive::text_iarchive ia(ifs);
ia >> myClassHashTable;
}
But I am getting an error as -
error C2039: 'serialize' : is not a member of 'stdext::hash_map<_Kty,_Ty>'
I searched online for this error but didn't get much help. Also, I checked in my boost installation serialization/hash_map.hpp does have a serialize() function in it. Same code worked for serialization of std::deque
. Can anyone tell me how should I change it to make it compile ?