我在类(class)的私有(private)部分声明了 int id。
private:
int id,age;
float gpa;
string last,first;
这段代码在我的文件中,用于显示和调用数组中的函数,并对 int id 进行排序。
student[i].sort_array(student[i].id,cap);
i++;
cout << i;
这是一个单独的文件,我把我的函数放在那里,如果我 student[i].put(cout) 数据,我能够显示数组的内容。我不确定如何传入一个整数,该整数会出现在我类(class)的证明部分
void student::sort_array(int student[i].get(id),int n)
{
int j,temp;
for(j=0;j<n-1;j++)
{
//if out of position switch the out of align number
if(student[j]<student[j+1])
{
temp = student[j];
student[j] = student[j+1];
student[j+1] = temp;
}
}
最佳答案
正常的方法是有一个bool student::compareAges(Student const& otherStudent)
方法,并将其作为额外参数传递给比较函数。例如。这是 std::sort
的第三个参数当你不使用默认 operator<
时
关于c++ - 如何对在私有(private)中声明的整数进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10396527/