| | |
error: initial value of reference to non-const must be an lvalue
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 628
Reputation:
Solved Threads: 46
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:
it says
but if i do
it works fine.
Can someone explain the difference?
Thanks,
Dave
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:
C++ Syntax (Toggle Plain Text)
Scan.setAngleList(Scan.MakeLinearGrid());
C++ Syntax (Toggle Plain Text)
error: initial value of reference to non-const must be an lvalue Scan.setAngleList(Scan.MakeLinearGrid());
but if i do
C++ Syntax (Toggle Plain Text)
vector<vector<Vector3> > temp = Scan.MakeLinearGrid(); Scan.setAngleList(temp);
it works fine.
Can someone explain the difference?
Thanks,
Dave
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. If at first you don't succeed, keep on sucking until you do succeed.
![]() |
Other Threads in the C++ Forum
- Previous Thread: win32 app help
- Next Thread: Need help with an exercise program (probably too easy for you guys)
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






