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