如何序列化boost :: uuids :: uuid

时间:2012-05-25 14:03:40

标签: serialization boost uuid

我目前在项目中使用boost :: uuids :: uuid,我想序列化包含boost :: uuids :: uuid的对象。我尝试了下面的简单示例,但是我收到了一个错误:

/usr/include/boost/archive/basic_text_oprimitive.hpp:92:错误:'运营商<<'中没有匹配''((boost :: archive :: basic_text_oprimitive> *)this) - >提升:: archive :: basic_text_oprimitive> :: os<< t'

如果有人可以帮助我的话,我会真的很高兴。

#include <fstream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

class classA {
public:
    classA() : id(boost::uuids::random_generator()()) {}
private:
    friend class boost::serialization::access;
    boost::uuids::uuid id;
    template <class Archive>
    void serialize(Archive& ar, const unsigned int version) {
        ar & id;
    }
};

int main(void) {
    classA a;
    std::ofstream ofs("uuid.txt");
    boost::archive::text_oarchive oa(ofs);
    oa << a;
    ofs.close();
    return 0;
}

1 个答案:

答案 0 :(得分:3)

包含<boost/uuid/uuid_serialize.hpp>以启用uuids的序列化。 http://www.boost.org/doc/libs/1_42_0/libs/uuid/uuid.html#boost/uuid/uuid_serialize.hpp