这是功能:
template <class T>
bool DeleteRecord(List<T> *list, T record)
{
T temp, check_ls;
bool del = false;
cout << "\nDeleting record......";
strcpy(temp, record);
for (int i = 1; i <= (*list).size(); i++)
{
(*list).get(i, check_ls);
if (check_ls == temp){
(*list).remove(i);
del = true;
break;
}
}
if (del){ return true; }
else { return false; }
}
如果是findID:
string findID(){
string id;
bool valid = false;
while (!valid){
cout << "\nEnter ID of Student: ";
cin >> id;
valid = true;
if (id.length() != 7)
{
cout << "\nError! Enter 7 digits";
id = "";
valid = false;
}
else
{
if (!alldigit(id))
{
valid = false;
cout << "\nError! Enter digit only.";
}
}
}
return id;
}
到目前为止这是我的代码(main.cpp)
int main(){
system("cls");
cout << "Delete Record\n";
//cout << findID().c_str();
id=findID();
cout << id;
if (DeleteRecord(stulist, id)){ cout << "Success! Record deleted.\n"; }
else { cout << "\n\nError! No such record.\n"; }
cout << "\nInfo: " << (*stulist).size() << " record(s) remaining.\n\n";
system("pause");
return 0;
}
当我调用DeleteRecord函数时出现问题。 它说没有函数模板的实例匹配参数列表。 有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
您的功能就像
bool DeleteRecord(List<T> *list, T record)
你的论点是错的。我猜它List
导致了麻烦。请尝试删除*
。