I have a function Scan.MakeLinearGrid() which returns a vector<vector<Vector3> >

I have another function that is made to accept this type of thing:
Scan.setAngleList(vector<vector<Vector3> >);

But if I call it like this:

Scan.setAngleList(Scan.MakeLinearGrid());

it says

error: initial value of reference to non-const must be an lvalue
    Scan.setAngleList(Scan.MakeLinearGrid());

but if i do

vector<vector<Vector3> > temp = Scan.MakeLinearGrid();
Scan.setAngleList(temp);

it works fine.

Can someone explain the difference?

Thanks,
Dave

Your Vector3 is missing the appropriate copy constructor.

A good rule of thumb is if you use any one of copy constructor, assignment operator, or virtual destructor, then you need all three. (Not always, but usually.)

Hope this helps.

I have neither an assignment operator or virtual destructor, so then why do i need a copy constructor?

Can you give a simple example of each of those?

What does setAngleList do? When you say Scan.setAngleList(Scan.MakeLinearGrid()); it passes a temporary object to the method. If setAngleList doesn't modify the object, you should make it a const reference anyway because that's both safer and more flexible in what you can pass. If setAngleList does modify the object, you shouldn't be passing a temporary at all, this call has a logical error that's luckily being caught by the compiler, and the working example you gave is the way to fix the error.

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