我看到這個問題的許多不同的答案,並已經看了很多人,但我無法找到我的問題的答案。 我有這樣的錯誤需要左值操作數需要作爲左操作數的分配C++在排序
左值作爲轉讓
我使用冒泡排序功能在我的對象數組
void BubbleSort(Student* student=new Student[5])
{
double temp;
for(int i2=0; i2<=4; i2++) {
for(int j=0; j<4; j++) {
if(student[j].getBal() > student[j+1].getBal()) {
temp = student[j].getBal();
student[j] = student[j+1];
student[j+1].getBal() = temp;
}
}
}
}
在我的班級排序雙重價值的左操作數
double getBal()
{
return this->bal;
}
void setBal(double bal)
{
this->bal=bal;
}
getBal()' – MokaT
'Student * student = new Student [5]'作爲默認參數的返回類型是純粹的邪惡。你怎麼知道你是否應該刪除參數? – Bathsheba
您的交換邏輯不正確,突然間您有兩個相同的學生,但有不同的餘額。 –