1
我有一個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();
}
這一點.... ISSSS ... C++的最棘手的解析! – chris
幫你一個忙,用clang編譯。 –