我不明白這個函數的問題是什麼,我在過去做過類似於這個的東西,它工作正常,但現在當我嘗試運行此函數時,我得到錯誤無法取消引用矢量迭代器
"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 –