Saving memory address of a function

Hey rrrybody,
Im working on a program and part of it uses a window manager that i made - It basically just creates another window within the program - My problem is i want to be able to add buttons to the windows its making but for that i want to be able to change the function it calls when its pressed
for example:
1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
    int id = -1;

    WindowManager Windowmanager;
    id = Windowmanager.AddWindow(x, y, width, height);
    Windowmanager.AddButton(id, x, y, width, height, text, void (*foo)());
}

void foo()
{
    DoStuff();
}


And in the WindowManager class
1
2
3
4
void WindowManager::AddButton(int x, int y, int width, int height, string text, void (*foo)())
{
    //Save function address for later use? 
}


Sorry i didnt really know how to explain this X)
Last edited on
You can declare a variable of type void (*foo)(). Actually, you should typedef this type so you get consistent use throughout your project:

1
2
3
4
5
typedef void (*fooType)();
//Now you can declare variables of type fooType:
fooType myFunctionPointerVariable;
//And you can assign it and even execute the function pointed to by this pointer:
myFunctionPointerVariable(); //There!  Executed. 


Look up in this site's tutorial or elsewhere information about function pointers.
Sweeeet, thats exactly what i need - Thank you :)
Topic archived. No new replies allowed.