学生班:
class Student:public Persone, public Subjects{...}
学生班有这两个方法:
void setAr(int ar){
this->arabic = ar;
}
int getAr(){
return arabic;
}
我希望能够使用另一个班级老师更改学生笔记。
老师课上的方法:
void setStudentNote(Student student, int note){
bool access = false;
for(int i=0;i<Groups.size();i++){
if(student.showGroup()==Groups[i])
access = true;
}
if(access){
if(Subject==Ar){
student.setAr(note);
cout << student.getFname() << " "<<student.getLname() <<" " <<Subject << " note: " << note << endl;
}
}else{
cout << "error, this student is not in your group!";
}
}
使用方法时 void setStudentNote(Student Student, int note) 值 Student.arabic 未更改。
copy。要更改原始版本,请使用(可变的)引用。
void setStudentNote(Student& student, int note)
请注意单词 Student
后面的 & 符号。
Student&
是对
Student
的非常量左值引用,这意味着对变量的修改将影响调用者的变量。