我在通过非模板函数传递模板函数的参数时遇到了一些麻烦。
假设我有这个:
template <class T>
void A(Array <T> &A) {
cout << "here";
}
void menu(Array<myType>& fooList) { // my type specified class type, created by me.
cout << "enter option ";
cin >> a;
switch {
case 1: A(fooList); break;
}
}
我希望这个例子足够清楚。这可能吗?我可以将参数从非模板函数传递到模板函数吗?
编辑: - 自我尝试构建的原型以来的实际代码没有帮助。
域.h
template <class T>
void printAll(Array <T> &DBst, Array <T> &DBas){
for(int i=0; i<DBst.lenght; i++){
DBst.M[i].printStudent();
std::cout<<" ___ ";
DBas.M[i].printAssgn();
std::cout<<std::endl;
}
}
控制器.h
template <class T>
void _printAll(Array <T> &DB1, Array <T> &DB2){
cout<<"List of students with their Assignment!"<<endl;
printAll(DB1, DB2);
cout<<"done!"<<endl;
}
菜单.cpp
void Menu::mainMenu(Array <Student> &DBst,Array <Assignment> &DBas){
showMainMenu();
int ret = Menu::intInputHandler();
while(ret){
switch(ret){
case 1:studentMenu(DBst,DBas);break;
case 2:assignmentMenu(DBst,DBas);break;
case 3:statsMenu(DBst,DBas);break;
case 4:_printAll(DBst,DBas);break; //// ERROR ***
case 0:/*exit*/;break;
default:cout<<"Wrong option selected!";break;
}
}
}
菜单.h
class Menu{
public:
void showMainMenu();
void showStudentMenu();
void showAssignmentMenu();
void showStatisticsMenu();
string stringInputHandler();
int intInputHandler();
void mainMenu(Array <Student> &,Array <Assignment> &);
void studentMenu(Array <Student> &,Array <Assignment> &);
void assignmentMenu(Array <Student> &,Array <Assignment> &);
void statsMenu(Array <Student> &,Array <Assignment> &);
};
*..\Menu.cpp:90:29: error: no matching function for call to '_printAll(Array<Student>&, Array<Assignment>&)'