哪位C++语言的高手帮我看看这个程序为什么通不过编译

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:45:28
#include<iostream>
using namespace std;
class Student//声明一个类
{
public:
Student(int n,float s):num(n),score(s){}
float getscore();
private:
int num;
float score;
};
float Student::getscore()
{return score;}
int main()
{
Student stud[5]={Student(101,78.5),Student(102,85.5),
Student(103,98.5),Student(104,100.0),Student(105,99.5)};
float max(stud);
cout<<max(stud)<<endl;
getchar();
return 0;
}

float max(Student *p)
{
float zuida=p->getscore();
for(int w=1;w<5;w=w+1,p=p+1)
{
if(zuida<(p+1)->getscore())
zuida=(p+1)->getscore();
}
return zuida;
}
这个有什么错误 错在哪里? 具体是哪一步出问题了?
: error C2440: 'initializing' : cannot convert from 'class Student [5]' to 'float'
There is no context in which this conversion is possible
: error C2064: term does not evalua

Student(103,98.5),Student(104,100.0),Student(105,99.5)};
float max(stud); //想在这声名函数是吧 参数改成Student *
cout<<max(stud)<<endl

#include<iostream>
using namespace std;
class Student//声明一个类
{
public:
Student(int n,float s):num(n),score(s){}
float getscore();
private:
int num;
float score;
};
float Student::getscore()
{return score;}

float max(Student *p)
{
float zuida=p->getscore();
for(int w=1;w<5;w=w+1,p=p+1)
{
if(zuida<(p+1)->getscore())
zuida=(p+1)->getscore();
}
return zuida;
}

int main()
{
Student stud[5]={Student(101,78.5),Student(102,85.5),
Student(103,98.5),Student(104,100.0),Student(105,99.5)};
float a = max(stud);
cout<<a<<endl;
getchar();
return 0;
}

定义对象时不可以对其私有成员赋值
#include<iostream>
using namespace