供参考:
#include<iostream>
using namespace std;
class Student{
private:
int xh;
int cj;
public:
Student(int x,int y)
{
xh = x;cj = y;
}
void max(Student *s);
};
void Student::max(Student *s)
{
int i,a,k=0;
a=s[0].cj ;
for(i=0;i<5;i++)
if(a < s[i].cj)
{a=s[i].cj;k=i;}
cout<<s[k].xh<<","<<s[k].cj<<endl;
}
int main()
{
Student s[5]={Student(2,90),Student(45,23),Student(7,98),Student(4,87),Student(21,45)};
//void max(student*s)
Student*p;
p->max(s);
return 0;
}
max 函数有定义吗?他错误报的是max函数没有定义