• Advertisement
Sign in to follow this  

Each iterator comparison

This topic is 428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i just want to erase each object from two lists.

 

 

here is my code

list<CObj*>::iterator iter = m_ToolObjList.begin();
list<CObj*>::iterator iter_end = m_ToolObjList.end();

/*



continue for get delete for object


*/

TCHAR tcDelKey[256];
		
_tcscpy_s(tcDelKey, (*iter)->GetMeshKey());

::Safe_Release(*iter); // first release and delete object

list<CObj*>::iterator objlist_iter = CObjMgr::GetInstance()->Get_ObjListForKey(tcDelKey)->begin();
list<CObj*>::iterator objlist_iter_end = CObjMgr::GetInstance()->Get_ObjListForKey(tcDelKey)->end();

//this ObjMgr is map Container. map<wstring, CObj*>
//Found list from tcDelkey and return it



for (objlist_iter; objlist_iter != objlist_iter_end; ++objlist_iter)
{
	if (objlist_iter == iter) // this is why i don't know crash here = Problem Point
		{
			CObjMgr::GetInstance()->Get_ObjListForKey(tcDelKey)->erase(iter);
			break;
		}
}

m_ToolObjList.erase(iter);
		 

problems arise from comparing "objlist_iter" and "iter"

 

i don't know what the problem is...

 

i'd appreciate it if you could help me.

Share this post


Link to post
Share on other sites
Advertisement

Your are comparing the iterators while you really want to compare the value of the items in the two lists you are comparing. I would think changing your problematic line to

if(*objlist_iter == *iter) 

should solve the problem. The next problem is that you are trying to erase an object from a list with an iterator of a different list:

CObjMgr::GetInstance()->Get_ObjListForKey(tcDelKey)->erase(iter);

iter is an iterator of m_ToolObjList. You should

CObjMgr::GetInstance()->Get_ObjListForKey(tcDelKey)erase(objlist_iter);

Share this post


Link to post
Share on other sites

I think you can also just skip searching manually with a for loop and just do:

CObjMgr::GetInstance()->Get_ObjListForKey(tcDelKey)->remove(*iter);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement