I am getting an Access Violation on erasing the vector in the below code. I tried to see where exactly the exception occurred in erase function of vector.h and could identify that _Move throws an access violation. Could you please help me how can I resolve this issue.
STDMETHODIMP SomeFunction(...)
{
vector<shared_ptr<CommandInfo>> f_Commands;
vector<shared_ptr<CommandInfo> >::iterator it = g_commands.begin();
while (it != g_commands.end())
{
if (SpecificConditionIsTrue)
{
it++;
continue;
}
f_Commands.push_back(*it);
it = g_commands.erase(it);
}
finishedCommands.clear();
return S_OK;
}
class ATL_NO_VTABLE IRsi
{
protected:
vector<shared_ptr<CommandInfo> > g_commands;
};
Exception at "_Move" call in vector
iterator erase(const_iterator _Where)
{ // erase element at where
_Move(_VIPTR(_Where) + 1, this->_Mylast,
_VIPTR(_Where));
_Destroy(this->_Mylast - 1, this->_Mylast);
--this->_Mylast;
return (_Make_iter(_Where));
}