I am trying to create an array of function pointers, with the ability to add functions. So I have to expand my array with each new function. My only problem is that every time I add a function only the last function I add executes, the other ones just crash, which my guess is that it did not correctly assign the pointer value. Here is my function:
void MyClass::AddCommand(String command,FUNCPTR function)
{
//Get original size
int commandListSize = m_commandList.GetCount();
//First make a copy, should have [commandListSize+1]
FUNCPTR* m_commandFunctionsCopy = m_commandFunctions;
delete m_commandFunctions;
//not make sure we make a new array with the correct size
//Size has to add one to old expected size, so [commandListSize+2]
m_commandFunctions = new FUNCPTR[commandListSize+2];
//Add a command to the list
m_commandList.Add(command);
//Fill all the slots with the correct functions
for(int x=0;x < commandListSize;x++)
{
m_commandFunctions[x] = m_commandFunctionsCopy[x];
//memcpy((char*)&m_commandFunctions[x],(char*)&m_commandFunctionsCopy[x],sizeof(m_commandFunctionsCopy[x]));
}
//fill it with the new function and a NULL ending
m_commandFunctions[commandListSize] = function;
m_commandFunctions[commandListSize+1] = '\0';
}