I'm trying to add an object to an object array passed as an argument. Specifically, I have an array of buttons and I am adding a back button to the button array. How can I correctly do this? When I try the code below I get some weird glitches with the buttons passed from the original pointer array.
int createMenu(Button buttons[], int size)
{
//Stuff here
}
int menu(Button buttons[], int size, bool back)
{
Button * newButtons[size + 1];
for (int i = 1; i <= size; i++)
*newButtons[i] = buttons[i];
Button back(25, 19, "Back"); //Creates back button object
*newButtons[0] = back;
return createMenu(*newButtons, size + 1);
//Makes menu with the back button
}
Any help is appreciated.
createMenuButton *newButtons[size+1];is illegal (although some compilers offer this as an extension). Also, it is not possible to resize them at runtime.