i'm working on a console game, and am trying to implement a menu system, what i have so far is a function that will draw out the menu and take the input and return a value based on the menu choice, and i wanna use that return value as the parameter of another function which will perform actions based on what the choice was (play, load, credits, quit). my first attempt was to chuck the function as a normal function call in the parameter assuming that the return would be used as the parameter, but what actually happens is that the return of the functions used as the parameter will cause the calling function to return with the same value as well.
i'm assuming, therefore that i will need to use function pointers to pass the function in as a parameter and get the return value that way, however, for some reason my function parameters aren't working. any help would be much appreciated.
//prototypes
int menu();
int DoAction(int (*choice)());
//function implementation
int menu()
{
int x = 14;
int y = 0;
char input = '\0';
int DoAction(&menu); isn't a function call. It's a declaration of a variable named DoAction of type int that you're trying to initialize with a function pointer. Remove the leading int from the statement.
Also, it appears you are using conio.h and related functions. I would recommend not using them. conio.h is not a part of any standard. You mostly only see them being used in ancient C++ tutorials that predate the standardization.
int DoAction(&menu); isn't a function call. It's a declaration of a variable named DoAction of type int that you're trying to initialize with a function pointer. Remove the leading int from the statement.
oh wow, thats the kind of stupid mistake you make when your up at 2am after working customer service all day. thanks for spotting my blunder!
Also, it appears you are using conio.h and related functions. I would recommend not using them. conio.h is not a part of any standard. You mostly only see them being used in ancient C++ tutorials that predate the standardization.
i use conio.h for kbhit() and getch() which, may be old and not standardized but seem to do the job, especially when i am basing movement around the arrow keys without having to delve into winapi.