2
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;
}
但我得到一个错误 -序列化stdext ::使用的hash_map升压串行化库
error C2039: 'serialize' : is not a member of 'stdext::hash_map<_Kty,_Ty>'
我在网上搜索了这个错误,但并没有得到太多的帮助。另外,我检查了我的boost安装序列化/ hash_map.hpp中有一个serialize()函数。相同的代码可用于序列化std::deque
。任何人都可以告诉我,我应该如何改变它来编译它?
不是你所需的东西,但谷歌Sparsehash图书馆地图来与一些内置的序列化支持,尽管与Boost序列化完全分开。 – doublep 2010-09-07 20:09:03
http://stackoverflow.com/questions/23764249/c-boost-serialization-error-for-hash-map-with-custom-objects-as-key/23768271#23768271 – sehe 2015-01-10 16:57:15