所以我正在尝试使用排序功能(类似于气泡)并将一个对象传递给它。如果该对象更大(按字母顺序),则 switch 然后返回 true 并在它之前切换它。尽管在 if 语句中,我不断收到错误消息,mySort()
其中显示“arr[j] 中的运算符 [] 不匹配”,但据我了解,我正在传递一个对象数组,对吗?为什么会发生这种情况,我该如何解决?
这是司机
#include <iostream>
#include <fstream>
#include <string>
#include "phoneEntry.h"
using namespace std;
void mySort(PhoneEntry &arr, int size)
{
bool inOrder = false;
string temp;
for (int i = size - 1; i > 0 && !inOrder; i--)
{
inOrder = true;
for (int j = 0; j < i; j++)
{
if(arr.alphaGreater(arr[j]))
{
inOrder = false;
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
};
int main()
{
const int MAXNUM = 500;
PhoneEntry entry[MAXNUM];
ifstream filezilla;
filezilla.open("phone.txt");
int count = 0;
if(filezilla)
{
while(count < MAXNUM && entry[count].readEntry(filezilla))
{
count++;
mySort(entry[count], count);
}
for(int i = 0; i < count; i++)
{
entry[i].writeEntry(cout) << endl;
}
}
else
{
cout << "404" << endl;
}
return 0;
}
文本排序 (http://pastebin.com/HE8Rsmbg)