如何序列化多维数组,使用boost的类成员?

时间:2013-07-17 10:44:59

标签: c++ serialization boost

http://robot.kaist.ac.kr/haptics/chai3d-2.0.0_Doc/resources/html/structc_matrix3d.html

cMatrix3d有一个班级数据成员double m [3][3];

现在纠正我,如果我错了:序列化这个类的实例我需要添加这个

private:
    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & m;//I think this is probably wrong, see error
    }

到班级定义,对吧?

我收到此运行时错误:client.exe中0x758c9617处的未处理异常:Microsoft C ++异常:内存位置处的boost :: archive :: archive_exception

当我尝试从存档反序列化到对象实例时,在客户端

std::istringstream iss(recvd_msg);
boost::archive::text_iarchive ia(iss); 
            cMatrix3d rot;
            ia>>rot;

1 个答案:

答案 0 :(得分:0)

尝试

private:
    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        for (int i = 0; i != 3; ++i)
        {
            ar & m[i];
        }
    }