9

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

/usr/include/boost/archive/basic_text_oprimitive.hpp:92: 错误:'operator<<' 在 '((boost::archive::basic_text_oprimitive >*)this)->boost::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;
}
4

1 回答 1

4

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

于 2014-12-28T18:59:25.497 回答