boost :: serialize和std :: chrono :: system_clock :: time_point

时间:2013-11-21 12:39:55

标签: c++ serialization boost c++11

我正在尝试使用boost :: serialize序列化包含std :: chrono :: system_clock :: time_point的类。

template <class Archive> void serialize(Archive& ar, unsigned int version) {
    ar & timePoint_;
}

然而我收到错误:

错误1错误C2039:'serialize':不是'std :: chrono :: time_point&lt; _Clock&gt;'的成员c:\ boost_1_54_0 \ boost \ serialization \ access.hpp 118

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

使用

boost::serialization::make_binary_object(void * t, size_t size);

boost/serialization/binary_object.hpp可以像这样使用:

std::chrono::system_clock::time_point tp;
ar & boost::serialization::make_binary_object(&tp, sizeof(tp));

答案 1 :(得分:0)

我设法使用以下侵入函数(在具有timepoint_作为成员函数的类中)使其工作

template <class Archive> void serialize(Archive& ar, unsigned int version) {
    char * ptr = reinterpret_cast<char *>(&timePoint_);
    for( int i = 0; i < sizeof(timePoint_); ++i)
        ar & ptr[i];
    /*snip*/
}