Trying to erase an element from a vector. I know this is an expensive operation, but I am not worried about performance.
My function is based on this msdn excerpt which provides an example of how to create, initilize and use a vector class iterator object which I plan to pass into erase(), which accepts iterator agrument(s).
As per the example, I have created an initialized an iterator; however, dev-cpp is giving me the following errors:
327 F:\Dev-Cpp\database2.cpp `Manager::vStaff' cannot appear in a constant-expression
327 F:\Dev-Cpp\database2.cpp template argument 1 is invalid
327 F:\Dev-Cpp\database2.cpp template argument 2 is invalid
327 F:\Dev-Cpp\database2.cpp `iterator' does not name a type
328 F:\Dev-Cpp\database2.cpp `Iter' undeclared (first use this function)
Here is the code, line #327 highlighted.
Using namespace std:
What am I missing/doing wrong?Code:void Manager::delete_staff() { vector<vStaff>::iterator Iter = vStaff.begin(); bool found = false; string name; int i = 0; cout << "\n\n\tEnter name o' staff to delete: "; cin >> name; while(!found && i < vStaff.size()) { if(vStaff[i] == name) found = true; i++; } if(!found) cout << "\n\n\t\.......... Name Not Found! **"; else { vStaff.erase(Iter + i); cout << "\n\n\tStaff Removed."; Sleep(1500); } }



LinkBack URL
About LinkBacks


