Hello List,
I'm creating a Button where I want to add a function setActionOnReleased(func aFunction);
From any class I'd like to instantiate this Button class and send it the function I want to execute.
I found some reference to using member function pointers ( http://bytes.com/topic/c/answers/569262-passing-function-argument ),
but I'd like to send the function pointer to another class ( Button ).
--Button.h:
class Button{
public:
typedef void (Button::*func)();
func onUp;
Button();
void setActionOnReleased(func onReleasedFunction);
void mouseReleased(ofMouseEventArgs & mouse);
};
--Button.cpp:
#include "Button.h"
Button::Button(){
}
void Button::setActionOnReleased(func onReleasedFunction){
onUp=onReleasedFunction;
}
void Button::mouseReleased(ofMouseEventArgs & mouse){
printf("mouse released");
(ouUp)();
}
and from any class I'd like to call:
void SettingsButton::connect(){
printf("connecting...");
}
button=new Button();
button->setActionOnReleased(&connect);