C++指针问题
#include<iostream>#include<string>
#include<iomanip>
using namespace std;
class Student
{
public:
Student(string n,int nu,int s)
{
name=n;
number=nu;
score=s;
}
string name;
int number;
int score;
void out();
friend void Max(Student *,Student *);
};
void Student::out()
{
cout<<setw(8)<<name<<setw(8)<<number<<setw(8)<<score<<endl;
}
void Max(Student *p,Student *pm)
{
for(int i=0;i<5;i++)
{
if((*(p+i)).score>(*pm).score)
{
*pm=*(p+i);
}
}
}
int main()
{
Student Stud[5]={Student("LX",01,01),Student("LD",02,02),Student("GD",03,03),Student("PX",04,04),Student("SYL",05,05)};
Student *p1=&Stud[0];
Student *p2=&Stud[1];
Student *p3=&Stud[2];
Student *p4=&Stud[3];
Student *p5=&Stud[4];
cout<<setw(8)<<"name"<<setw(8)<<"number"<<setw(8)<<"score"<<endl;
(*p1).out();
(*p2).out();
(*p3).out();
(*p4).out();
(*p5).out();
Student *p=&Stud[0];
Student *pm=("Max",0,0);
Max(p,pm);
(*pm).out();
return 0;
}
编译没错误,运行报错,是为什么?