I am using a vector to manage the data within my app and need to delete elements within the vector.

The code below uses the remove_if and erase methods to achieve this however it only ever removes the last element of the vector and not the one allocated by the remove_if. Irrespective which element in the vector is to be removed only the last element is erased.

The code below first searches the vector for the required element and changes the data so that the SomeFunc function will return true indicating that this is the element to remove.

I then use the remove_if to process the vector in preparation for the erase.

Code:
bool SomeFunc(InsertionData& item)
{
	if (item.GetEntry() == 0 )
       return true;
    return false;
}



void FaultEntry::DeleteListing(int Entry)
{
    ListingDataVector::iterator ListingIterator;
    int VectorCount = 0;
    bool DoErase = false;
    
     if (Entry != 0)
    {
        for(ListingIterator = ListingsVector.begin(); ListingIterator != ListingsVector.end(); ListingIterator++)
        {
            if(ListingIterator->GetEntry() == Entry)
           {				
	ListingIterator->ClearContents();
	DoErase = true;
           }
        }

        if(DoErase)
       {
            ListingIterator = remove_if(ListingsVector.begin(), ListingsVector.end(), SomeFunc);

             this->ListingsVector.erase(ListingIterator, ListingsVector.end());
        }
    }
}
Can any please provide any insights?