error:non-lvalue in assignment

mach[i-1].time_ol(m)=mach[i].time_ol(m);
mach[i].time_ol(m)=temp;
Ιn both orders I had the same error...
What does mach[i-1].time_ol(m) return? If it's a temporary it you can't assign to it.
return float ,mach[i] is an array of objects
what does mean that error???
Last edited on
The float returned will only exist on that line so assigning to it doesn't make sense. If it was a reference that was returned it makes more sense and you wouldn't have that error message. The question is, what are you trying to do?
machine m_short(machine mach[], int m)
{
int i;
float temp;
bool swapped=false;

do {

for(i=1;i<m;i++)
{
if (mach[i-1].time_ol(m)>mach[i].time_ol(m)) {
temp=mach[i-1].time_ol(m);
mach[i-1].time_ol(m)=mach[i].time_ol(m);
mach[i.].time_ol(m)=temp;
swapped true;
}
if (mach[i-1].time_ol(m)==mach[i].time_ol(m)) {
for (i=1,i<m,i++) {
temp=mach[i-1].cost_ol(m,cost_1);
mach[i-1].cost_ol(m,cost_1)=mach[i].cost_ol(m,cost_1);
mach[i].cost_ol(m,cost_1);
swapped=true;
}
}
}

} while (!swapped) ;
return(mach[0].time_ol(m)/mach[m].cost_ol(m,cost_1));
}
i wanted to sort by time the objects mach[i],
after that i would like to sort by time the objects mach[i] if ..see above ..
Isn't this what you want?
1
2
3
temp=mach[i-1];
mach[i-1]=mach[i];
mach[i]=temp;


using std::swap you can write it as
std::swap(mach[i-1], mach[i]);
yeah thanks!
i hadn't think like that.
Topic archived. No new replies allowed.