Hi
I am allocating memory space and adding nodes like this:
CSprite* pNewSprite = new CSprite; // Create new sprite
pNewSprite->iData = iChoice; // Attach data
EnemyList->AddNode(pNewSprite); // Send to AddNode
and also in the ::AddNode:
void CLinkedList::AddNode(VOID* pData)
{
CNode* pNewNode = new CNode; // Create the Node
pNewNode->pData = pData; // Assign the Sprite data
...
m_iNumberOfNodes++;
}
And then (trying) to delete them like this:
// Clear up and delete resources
CurrentNode = EnemyList->m_pHeadNode->pNext; // Point to first in list
while (CurrentNode != EnemyList->m_pEndNode)
{
delete CurrentNode->pData; // <======= Second time around access violation ========
delete CurrentNode;
CurrentNode = CurrentNode->pNext; // Go to next in the list
}
delete CurrentNode;
delete EnemyList;
The second time around the CurrentNode->pData is presumabley NULL. You see I am allocating memory for the Sprite and the Node so need to delete them both. Whats the proper way...? Do I have to cast them to a Sprite* then delete the objects then the node...?