I'd. like to make introductory comment saying the following code is a solution of old academic exercise so It's old code:
Code:
#include <iostream>
#include "widget.h"
using namespace std;
class MyButton : public Button {
TextField* tf;
public:
MyButton(TextField* t) : tf(t) {}; // costruttore
void action(void *data);
};
void MyButton::action(void *data) {
cout << tf->getTex() << endl;
}
int main() {
Window* w = new Window;
TextField* t = new TextField;
Mybutton* b = new Mybutton;
w->setTitle("Window");
w->add(t);
w->add(b);
};
I think that
HTML Code:
Mybutton* b = new Mybutton
is wrong
because when It is instantiated MyButton class, It's called Constructor of MyButton which needs TextField pointer as parameter.
I should write this code:
Code:
Mybutton* b = new Mybutton(t);
What do you think ?