我不明白这个函数的问题是什么,我在过去做过类似于这个的东西,它工作正常,但现在当我尝试运行此函数时,我得到错误无法取消引用矢量迭代器
"Unable to dereference vector iterator"
这是继这是有道理的,因为这是它被dereferenced其中线curr->setName(new_name);
。也只是为了清楚所有在这个方法中使用的函数和类自行工作,我只是没有为了空间而插入它们。
void System::modify(PC a){
char x;
curr = find(begin(comps), end(comps), a);
cout << "What would you like to modify:" << endl;
cout << "a - Name" << endl;
cout << "b - IP" << endl;
cout << "c - Password" << endl;
cin >> x;
if(x == 'a'){
string new_name;
cout << "What would you like to rename the computer to: ";
cin >> new_name;
curr->setName(new_name);
}
if(x == 'b'){
string new_IP;
cout << "What would you like the new IP address to be: ";
cin >> new_IP;
curr->setIP(new_IP);
}
if(x == 'c'){
curr->setNewPass();
}
else{
cout << "Choice is not valid" << endl;
return;
}
}
您是否检查确认'curr!= end(comps)'并且comps不是空的? – NathanOliver
@NathanOliver显然不是。 –
你应该检查'curr!= end(comps)'并决定如何处理一个不存在的PC –