Can anyone please explain/point out a good example of how to create and pass object(s) using a menu. I seem to find this a hard concept to fully understand. I will post the menu portion of my code below. I do not think the entire code is needed, but if required, I can re-post it. I seem to lose the object created, thereby am unable to do anything with the created object. Can anyone help?
Code:
int selection;
ArrayStack stack(0);
do
{
selection = mainMenu();
switch (selection)
{
int size, number;
case 1:
{
cout << "How many elements do you want the Stack to
have? ";
cin >> size;
createStack(stack, size);
break;
}
case 2:
{
cout << "Enter the number to Add(Push) onto the Stack: ";
cin >> number;
pushStack(stack, number);
break;
}
case 3:
{
cout << "Enter the number to Remove(Pop) off the
Stack: ";
cin >> number;
popStack(stack, number);
break;
}
case 4: CLS;
cout << endl
<< "Press the <ENTER> key to Exit the Program"
<< endl << endl;
exit(EXIT_SUCCESS);
break;
}//end switch
cout << endl << endl
<< "Press the <ENTER> key to return to the main menu.";
cin.get();
}while(selection != 4);
The three functions used in the menu:
createStack, pushStack, popStack
are passed a reference of the ArrayStack class and are declared in the main function, they are not part of the class.
I have tried every way that I can think of but seem to be unable to pass an object through the entire program without apparently losing it.
Any suggestions?
Thanks,
Alan