map/set iterator not incrementablemap/set iterator not incrementable

前端 未结 2 1880
-上瘾入骨i
-上瘾入骨i 2021-02-07 14:27
Driver::~Driver()
{
    AutoCritSec acsDriverList(m_csDriverList,true);
    DRIVERLIST::iterator it = m_DriverList.begin();
    for(;it!=m_DriverList.end();it++) 
    {
         


        
2条回答
  •  执念已碎
    2021-02-07 14:56

    The correct erase idiom for associative containers is as follows:

    for (auto it = container.begin(); it != container.end() /* not hoisted */; /* no inc. */ )
    {
        if (delete_condition)
        {
            container.erase(it++);
        }
        else
        {
            ++it;
        }
    }
    

提交回复
热议问题