I’ve got a Button class, like this:
class Button {
protected:
SDL_Rect box;
public:
Button(string id, int x, int y, int w, int h);
~Button();
virtual void handleEvent(SDL_Event event);
};
And I’ve got a special kind of Button, MyButton:
class MyButton : public Button {
public:
MyButton(string id, int x, int y, int w, int h);
~MyButton();
void handleEvent(SDL_Event event);
};
The thing is, I need the MyButton::handleEvent() method to return int instead of void. What is the most elegant way to do this?
EDIT: the reason I need this is because I need to know when MyButton was pressed in order to do some other things in other classes.
After all with the notion of inheritance
MyButtonis an instance ofButton. What this means is that you already have ahandleEventmethod defined inMyButtonand we cannot have to methods with the same name and with two different return types.This means that if you want to have a method that returns an integer you can
overloadyourhandleEventmethod inMyButtonwith an integer reference parameter and you can set its value in the reference.