sohel14_cse_ju sohel14_cse_ju - 2 months ago 15
C++ Question

Remove first item of vector

Here is my type :

struct Rule
int m_id = -1;
std::wstring name;
double angle;

Vector of that type :

std::vector<Rule>& topPriorityRules;

I am trying to erase first element:


But can't do it. Looks like i need to do iterator overloading.

Can any one suggest about iterator overloading for my struct?



std::vector<Rule>& topPriorityRules;

The correct way to remove the first element of the referenced vector is


which is exactly what you suggested.

Looks like i need to do iterator overloading.

There is no need to overload an iterator in order to erase first element of std::vector.

P.S. Vector (dynamic array) is probably a wrong choice of data structure if you intend to erase from the front.