Hey i’m trying to make a very simple GUI using SFML, and i want to be able to attach a function to my Button class in the constructor, as so the user can define what happens when the button is pressed.
I’ve worked a little before with GLUT and noticed these declerations:
glutReshapeFunc(Resize);
glutDisplayFunc(Draw);
Which apparently define what function should be called when the window is resized or displayed. I want something exactly like this for my button so upon construction you can define what function should be called. I want to be able to pass a function name just like glut, not having define a new class wich overides a virtual functin.
- I also doubt it’s possible however to pass parameters for these
called functions, as you never know what or how many there would be.
Am i right?
So anyway….. How do i accomplish this or something like it?? Thanks!
You can store a callback using e.g.
std::function(for C++0x;boost::functionis also available and has a similar interface).