Set function for an instance of a class
Hello ! I am currently working on a UI tool in C++ using SDL2 (already made one in Python with OOP and Pygame). I want to make buttons which each has a custom function named "click_event". I want to pass this function as an argument in the constructor "Button", but it gives me an error... class Button{ int x, y; int width, height; void click_event(); [...] public : Button(int x, [...], void (*click_event)()){ this->x = x; [...] this->click_event = *click_event; // This gives me an error [*] } [...] }; [*] : error: invalid use of member 'void Button::click_event()' (did you forget the '&' ?) void (*click_event)() is a pointer to the function, right ? So, *click_event is the function ? Please correct me if I'm wrong... Have a good day !