Monday 15 September 2014

c++ - Error about this lvalue required as left operand of assignment -



c++ - Error about this lvalue required as left operand of assignment -

this problem!!

for( = 0; <= max - 2; i++){ for( j = + 1; j <= max - 1; j++){ if(stud[i].getedad() < stud[j].getedad()){ temp=stud[i].getedad(); stud[i].getedad() = stud[j].getedad(); stud[j].getedad() = temp; } } }

source of problem believe

stud[i].getedad() = stud[j].getedad().

an lvalue (locator value) represents object occupies identifiable location in memory (i.e. has address). rvalues defined exclusion, saying every look either lvalue or rvalue. therefore, above definition of lvalue, rvalue look not represent object occupying identifiable location in memory

with said, assignment expects lvalue left operand i.e.

class="lang-cpp prettyprint-override">//here foo returns reference i.e lvalue ther's no problem in below code. int& foo() { homecoming globalvar; } int main() { foo() = 10; homecoming 0; } //whereas next 1 give error since homecoming value temporary object , assigning it. int foo() { homecoming globalvar; } int main() { foo() = 10; homecoming 0; }

c++

No comments:

Post a Comment