and that I want to add methods to this class for adding, removing and showing CMyObject items. In my previous implementations with MFC, I added a CMyObject pointer data member that pointed to the current item in the list:

CMyObject *  m_pCurrentObject;

This pointer is initialized to NULL in the constructor and then is assigned to every item added to the list.

My question is: should I use now an iterator (as a data member in CMyClass) to keep track of the current item in the list? 

Yes.

I know that iterators are invalidated with some operations such as erase(). Is there a better approach? 

std::list::erase only invalidates the iterators to the deleted items.  Iterators to other items are left intact.

---------
Ehsan Akhgari

www.farda-tech.com
List Owner: [EMAIL PROTECTED]

[Email: [EMAIL PROTECTED]]
[WWW: http://www.beginthread.com/Ehsan ]
 

Reply via email to