Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Boost反序列化对象具有nan或-nan值_C++_Boost_Boost Serialization - Fatal编程技术网

C++ Boost反序列化对象具有nan或-nan值

C++ Boost反序列化对象具有nan或-nan值,c++,boost,boost-serialization,C++,Boost,Boost Serialization,我最近询问了一个地图的反序列化问题,我在这里得到了答案: 我现在面临的问题是,我得到了一些点对象值的nan值。以下是一个序列化字符串示例: 22 serialization::archive 16 0 0 47 uploads/guest/another_project/90.step_1/90.step 0 0 1 0 0 0 1 0 0 0 0 1 9.00000000000000000e+01 1 0 0 -2.400000000000000000000e+01 1.00000000000

我最近询问了一个地图的反序列化问题,我在这里得到了答案: 我现在面临的问题是,我得到了一些
对象值的
nan
值。以下是一个序列化字符串示例:

22 serialization::archive 16 0 0 47 uploads/guest/another_project/90.step_1/90.step 0 0 1 0 0 0 1 0 0 0 0 1 9.00000000000000000e+01 1 0 0 -2.400000000000000000000e+01 1.000000000000000000000e+00 -2.500000000000000000000e+01 -2.400000000000000000000e+01 1.000000000000000000000e+00 2.500000000000000000000e+01
我决定在序列化和反序列化期间打印这些值,并显示正确的值

...
class Point
{
  friend class boost::serialization::access;
  friend std::ostream & operator<<(std::ostream &os, const Point &p);

  template<class Archive>
  void serialize(Archive &ar, const unsigned int version)
  {
    // save/load base class information
    ar & X & Y & Z;

    std::cout << "(" << X << ", " << Y << ", " << Z << ")" << std::endl; // OK
  }
...
};
还有另一个名为bendline的对象,我必须使用2个
对象创建它:这是我打印点的函数

  void ModelBend::makeBendLine(){
    gp_Pnt endPoint(
      startp.X,
      startp.Y,
      startp.Z
    );

    gp_Pnt dirVertex(
      startp.X - endp.X,
      startp.Y - endp.Y,
      startp.Z - endp.Z
    );

    bendLine_ = gp_Lin(endPoint, gp_Dir(dirVertex.X(), dirVertex.Y(), dirVertex.Z()));
    
    std::cout << "==========================================="  << std::endl;
    std::cout << "(" << startp.X << ", " << startp.Y << ", " << startp.Z << ")" << " ==== ";
    std::cout << "(" << endp.X << ", " << endp.Y << ", " << endp.Z << ")" << std::endl;
    std::cout << "==========================================="  << std::endl;
  }
void ModelBend::makeBendLine(){
gp_Pnt端点(
startp.X,
开始,
startp.Z
);
gp_Pnt直接顶点(
startp.X-endp.X,
开始时-结束时,
起始点Z-结束点Z
);
bendLine_uu=gp_Lin(端点,gp_Dir(dirVertex.X(),dirVertex.Y(),dirVertex.Z());

std::cout我更改了代码,并从序列化函数调用makeBendLine(),而不是在构造函数ModelBend()中调用,如下所示,现在一切正常:

template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
    // save/load base class information
     ar & boost::serialization::base_object<MFace>(*this);
     ar & mBendAngle & mBendDirection & startp & endp;

     makeBendLine();  // LIKE THIS
}
模板
无效序列化(存档和ar,常量未签名整数版本)
{
//保存/加载基类信息
ar&boost::serialization::base_对象(*this);
ar&MBendagle&mBendDirection&startp&endp;
makeBendLine();//像这样
}

序列化时是否需要执行该函数

可能不会。 因此,您有
正在保存/正在加载的特性

template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
    // save/load base class information
     ar & boost::serialization::base_object<MFace>(*this);
     ar & mBendAngle & mBendDirection & startp & endp;

     if(Archive::is_loading::value) makeBendLine();
}
模板
无效序列化(存档和ar,常量未签名整数版本)
{
//保存/加载基类信息
ar&boost::serialization::base_对象(*this);
ar&MBendagle&mBendDirection&startp&endp;
如果(存档::正在加载::值)makeBendLine();
}

(真正的问题是makeBendLine可能会触动内存进行名义上为
const
的保存操作)

因此,您从
序列化打印出来的结果表明,您没有从序列化/反序列化中得到nan,但您的问题标题表明您得到了nan。我有点困惑。显然,证据表明您的程序中的其他地方有一个bug。@john我不确定如何表示它。现在怎么样?我的观点是,没有证据表明序列化或反序列化是问题所在(事实上,证据正好相反)。根据您在这里介绍的内容,您的代码中似乎有其他地方的错误。但是如果无法看到代码的其余部分,则无法提供帮助。
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
    // save/load base class information
     ar & boost::serialization::base_object<MFace>(*this);
     ar & mBendAngle & mBendDirection & startp & endp;

     if(Archive::is_loading::value) makeBendLine();
}