我的结构有问题......或类似的东西。我有2个数组,其中一个被定义为Array <Student> DBst
,一个Array <Assignment> DBas
。事情是错过了,因为我的一个函数(模板形式)弹出一个错误它告诉我Class Assignment
没有函数setStudent(...)
但是我不知道为什么它会读取我的结构{ {1}}作为Assigment对象的集合。
Domain.h:
DBst
或者Controller.h:
template <class T>
void addStudent(int a, int b, std::string c,Array <T> &A){
A.M[a].setStudent(a,b,c);
cout<<"here";
}
Menuc.cpp:
template <class T1>
void _addStudent(Array <T1> &A){
int a,b;
string c;
cout<<"Enter ID:"<<endl;
cin>>a;
cout<<"Enter Group:"<<endl;
cin>>b;
cout<<"Enter Name:"<<endl;
cin>>c;
addStudent(a,b,c,A);
}
Menu.h:
void Menu::mainMenu(Array <Student> &DBst,Array <Assignment> &DBas){
showMainMenu();
int ret = Menu::intInputHandler();
switch(ret){
case 1:studentMenu(DBst,DBas);break;
case 2:assignmentMenu(DBas,DBst);break;
case 3:statsMenu(DBst,DBas);break;
case 4:_printAll(DBst,DBas);break;
case 0:break;
default:cout<<"Wrong option selected!";break;
}
Menu::mainMenu(DBst,DBas);
void Menu::studentMenu(Array <Student> &DBst,Array <Assignment> &DBas){
showStudentMenu();
int ret = Menu::intInputHandler();
switch(ret){
case 1:_addStudent(DBst);break;
case 2:_removeStudent(DBst);break;
case 3:_editStudent(DBst);break;
case 4:_printStudent(DBst);break;
case 5:_printAllStud(DBst);break;
case 6:_searchByID(DBst);break;
case 0:mainMenu(DBst,DBas);break;
default:cout<<"Wrong option selected!";break;
}
Menu::studentMenu(DBst,DBas);
}
Student.cpp:
class Menu{
public:
string stringInputHandler();
int intInputHandler();
void mainMenu(Array <Student> &,Array <Assignment> &);
void studentMenu(Array <Student> &,Array <Assignment> &);
void assignmentMenu(Array <Assignment> &,Array <Student> &);
void statsMenu(Array <Student> &,Array <Assignment> &);
};
我得到的错误是休息:
void Student::setStudent(int a,int b,string c){
this->ID = a;
this->group = b;
this->name = c;
}
编辑:
D:\c++\Begin\Lab6-8_UML/Domain.h:70:2: error: 'class Assignment'
has no member named 'setStudent'`
答案 0 :(得分:1)
它在您提供的代码中不可见,但我怀疑您使用addStudent<T>
参数(最后一个)调用某个Array<Assignment>
函数并且Assignment
类没有setStudent
方法。