我有一个 clss 学生,我在存储库的同一个标题中使用了它的成员函数,没有问题......但现在在这个函数中我得到一个错误:
..\StudentRepository.cpp:22:7: error: request for member 'setName' in 'st', which is of non-class type 'Student()'
这是功能:
void StudentRepository::loadStudents(){
ifstream fl;
fl.open("studs.txt");
Student st();
string s,ss;
int loc;
if(fl.is_open()){
while(!(fl.eof())){
getline(fl,s);
loc = s.find(",");
ss = s.substr(0,loc);
st.setName(ss);
}
}
else{
cout<<"~~~ File couldn't be open! ~~~"<<endl;
}
fl.close();
}
我不得不提到,在同一个文件中,我确实使用了它们,例如这个函数:
void StudentRepository::editStudent(Student A){
int i;
i = findByName(A.getName());
if( i != 0 || i != NULL){
students[i].setGroup(A.getGroup());
students[i].setId(A.getID());
}
else{
throw RepoException("The name does not exist!");
}
saveStudents();
}