void pointers? Why not use templates? =P
void LinkedList::retrieve(void *buffer, int index)
HVSTGFX::CAnimation *temp = 0;
sprites.retrieve((HVSTGFX::CAnimation*)&temp, index);
Anyway, look at this carefully. You're getting the address of the CAnimation pointer (effectively, CAnimation**), and then casting that into a CAnimation* and then casting it into a void*.
But the real problem is you then pass a copy of this,
not a reference, to the retrieve function. The copy gets assigned, then dropped off the stack.
If you want to pass a reference to the void* then have the parameter as void*& buffer. You probably won't be able to use void** because you can't then do *buffer = [whatever] because it will not know what *buffer is...
void LinkedList::retrieve(void*& buffer, int index)
{
node *current = firstNode;
if (current != 0)
{
for (int i = 0; i < indexCounter; i++)
{
if (i == index)
{
buffer = (void*)(current->data); // I assume here data is a pointer,
// if not, alter as needed.
return;
}
else
current = current->next;
}
}
}
HVSTGFX::CAnimation CSprite_State::getSprite(int index)
{
HVSTGFX::CAnimation *temp = 0;
sprites.retrieve((void*)temp, index);
return *temp;
}
Above code should work.
Alternatively just return the void* and cast it into a CAnimation* instead of using references and the like. Then you're getSprite function could just be one line
return *((CAnimation*)(sprites.Retrieve(index)));
Also calling retrieve a lot is going to be slow, but you're probably aware of that.
Though if you ask me, you really need something there in case of temp == 0...