求助:友元函数
#include<iostream.h>class student
{
private:
int number,grade;
char name[20];
public:
student(int num,int gra,char na[20])
{number=num;
grade=gra;
name[20]=na[20];}
void out(int num,int gra,char na[20])
{cout<<"姓名:"<<na<<"学号:"<<num<<"成绩:"<<gra<<endl;}
friend int compare(student &s1,student &s2);
};
int compare(student &s1,student &s2)
{
if(s1.grade>s2.grade)
cout<<"The better:"<<"姓名:"<<s1.name<<"学号:"<<s1.number<<"成绩:"<<s1.grade<<endl;
else
cout<<"The better:"<<"姓名:"<<s2.name<<"学号:"<<s2.number<<"成绩:"<<s2.grade<<endl;
return 0;
}
int main()
{
student s1(1,76,"Jane"),s2(2,81,"Jack");
s1.out(1,76,"Jane");
s2.out(2,81,"Jack");
int compare(s1,s2);
return 0;
}
Int 类型不对,该换什么