1

Given these two function declarations:

void initialize(int p, std::vector<Vector3> &);
std::vector<Vector3> toNurbsCoords(std::vector<Vector3>);

why does this work

Nurbs nurbs;
std::vector<Vector3> pts = nurbs.toNurbsCoords(points);
nurbs.initialize(degree, pts);

while this throws a compile time error?

Nurbs nurbs;    
nurbs.initialize(degree, nurbs.toNurbsCoords(points));
//error: no matching function for call to 'Nurbs::initialize(int&, std::vector<Vector3>)'
4

1 回答 1

3

因为临时不能绑定到非const引用。

nurbs.toNurbsCoords(points)是暂时的。在第一种情况下,您使用它初始化命名对象 - pts- 并传递它。在第二种情况下,您只需传递温度。

于 2013-10-17T09:55:25.583 回答