error: invalid initialization of non-const reference of type ‘float&’ from an rvalue of type ‘float’

mac2022-06-30  38

今天在编译c++代码的时候碰到了这个问题.即:

error: invalid initialization of non-const reference of type ‘float&’ from an rvalue of type ‘float’

相关函数调用栈为: inline void getPointFast(size_t index, float &x,float &y) const { x=this->x[index]; y=this->y[index];} inline void getPointWithoutWeight(size_t index,mrpt::math::TPoint2D &p) const { getPointFast(index,p.x,p.y); }

出现此编译问题的原因为: TPoint2D的结构类似为: struct TPoint2D{ double x, double y } 因此传入的p.x p.y为double类型, c++会默认转为float类型的临时变量。加粗样式 因此会出现题示错误。

最新回复(0)