4

I am trying to serialize a class that contains a std::chrono::system_clock::time_point with boost::serialize.

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

However I get the error:

Error 1 error C2039: 'serialize' : is not a member of 'std::chrono::time_point<_Clock>' c:\boost_1_54_0\boost\serialization\access.hpp 118

How do I fix this?

2 Answers 2

3

Use

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

from boost/serialization/binary_object.hpp wchich can be used like this:

std::chrono::system_clock::time_point tp;
ar & boost::serialization::make_binary_object(&tp, sizeof(tp));
Sign up to request clarification or add additional context in comments.

Comments

0

I managed to get it to work using the following intrusive function (in the class which has the timepoint_ as a member function)

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*/
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.