According to the documentation, CAtlList behaves like a double linked list, so removing one list item should not invalidate the pointers to other items. The POSITION
type references the memory location of a list item directly:
Most of the CAtlList methods make use of a position value. This value is used by the methods to reference the actual memory location where the elements are stored, and should not be calculated or predicted directly.
It seems this is not the case in atlcoll.h:
template< typename E, class ETraits >
void CAtlList< E, ETraits >::RemoveAt( POSITION pos )
{
ATLASSERT_VALID(this);
ATLENSURE( pos != NULL );
CNode* pOldNode = (CNode*)pos;
// remove pOldNode from list
if( pOldNode == m_pHead )
{
m_pHead = pOldNode->m_pNext;
}
else
{
ATLASSERT( AtlIsValidAddress( pOldNode->m_pPrev, sizeof(CNode) ));
pOldNode->m_pPrev->m_pNext = pOldNode->m_pNext;
}
if( pOldNode == m_pTail )
{
m_pTail = pOldNode->m_pPrev;
}
else
{
ATLASSERT( AtlIsValidAddress( pOldNode->m_pNext, sizeof(CNode) ));
pOldNode->m_pNext->m_pPrev = pOldNode->m_pPrev;
}
FreeNode( pOldNode );
}