读书人

使用map的时候无法清空map里面的数据,

发布时间: 2012-04-15 18:39:21 作者: rapoo

使用map的时候无法清空map里面的数据

C/C++ code
class Mytl{    //主程序代码}class MytlOSCfg{public:    map<CString,Mytl*> threadList;    CRITICAL_SECTION mytlThreadListLock;}class MytlDlg{public:    MytlOSCfg *osCfg = new MytlOSCfg;    afx_msg LRESULT CMytlDlg::StopAll(WPARAM wParam,LPARAM lParam)    {        EnterCriticalSection(&osCfg->mytlThreadListLock);        osCfg->threadList.clear();//在这里用SGList.empty()判断已经是空的了        updataThreadList();        LeaveCriticalSection(&osCfg->mytlThreadListLock);    }void CMytlDlg::updataThreadList(){    m_LBThreadsListItems.ResetContent();    if(!osCfg->threadList->empty())//这里向ListBox中添加数据的时候里面又有值了    {        for (map<CString,Mytl*>::iterator iter=threadList->begin();iter!=threadList->end();iter++)        {            m_LBThreadsListItems.AddString(iter->first);        }    }}};


这个要怎么弄了,下面有时候显示总是还有东西,要怎么做同步或都是处理就可以避免掉这些了

[解决办法]
clear() 函数清空不可以吗?
[解决办法]
clear()可以清空吧
[解决办法]
判断osCfg->threadList->empty() 时也要锁

读书人网 >C++

热点推荐