Start New Discussion within our Software Development Community

I have a function:
void CreateCostGrid(vector<ScanPoint> &Data, int whichcol, vector<LiDARScan> &LiDARGrid);

That I call like this:
CreateCostGrid(TestScan.getColumn(,, ModelScans);

But I get this:
error: initial value of reference to non-const must be an lvalue
CreateCostGrid(TestScan.getColumn(,, ModelScans);
(There is an arrow underneath the T in TestScan, i guess indicating that is there the problem is?)

This has been working for weeks and all of a sudden stopped working - so there is nothing wrong with any of the things you can't see here (ie. the ScanPoint class or the LiDARScan class).

Anyone know what this error means?



It is because you are trying to pass a temporary object to the function. Temps are const. Therefore your function header should be: void CreateCostGrid(const vector<ScanPoint> &Data, int whichcol, vector<LiDARScan> &LiDARGrid); If you want to modify the data, then your getColumn() function must return a non-const reference. vector<ScanPoint>& getColumn(...); Hope this helps.

This article has been dead for over six months. Start a new discussion instead.