S
sven_c_t
Hi!
Probably a newbie question. I´ve been working a bit with the widget
toolkit FLTK and I have been wondering why there is such a heavy use of
the new operator, when it does not seem to be nessesary (at least to
me). What follows is an example taken from the FLTK tutorial:
-------------
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(300,180);
Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!");
box->box(FL_UP_BOX);
box->labelsize(36);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
-------------
Both the object of the Fl_Window widget and the Fl_Box widget, is
created using the new operator. I dont see the point in using dynamic
memory allocation when it is not stricly nessesary. What is the
advantage in this situation?
Likewise Qt makes use of the new operator when dealing with widgets.
The following example is taken from an Qt tutorial:
-------------
#include <QApplication>
#include <QFont>
#include <QPushButton>
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(200, 120);
QPushButton *quit = new QPushButton("Quit", this);
quit->setGeometry(62, 40, 75, 30);
quit->setFont(QFont("Times", 18, QFont::Bold));
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
--------------
Again, I dont see the necessity for dynamic memory allocation, even
though it is not nessesary within this framework to think about
deleting the child widgets.
I hope that someone has an answer for me, because this question is
simply killing me...
Sven Creutz Thomsen
Probably a newbie question. I´ve been working a bit with the widget
toolkit FLTK and I have been wondering why there is such a heavy use of
the new operator, when it does not seem to be nessesary (at least to
me). What follows is an example taken from the FLTK tutorial:
-------------
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(300,180);
Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!");
box->box(FL_UP_BOX);
box->labelsize(36);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
-------------
Both the object of the Fl_Window widget and the Fl_Box widget, is
created using the new operator. I dont see the point in using dynamic
memory allocation when it is not stricly nessesary. What is the
advantage in this situation?
Likewise Qt makes use of the new operator when dealing with widgets.
The following example is taken from an Qt tutorial:
-------------
#include <QApplication>
#include <QFont>
#include <QPushButton>
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(200, 120);
QPushButton *quit = new QPushButton("Quit", this);
quit->setGeometry(62, 40, 75, 30);
quit->setFont(QFont("Times", 18, QFont::Bold));
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
--------------
Again, I dont see the necessity for dynamic memory allocation, even
though it is not nessesary within this framework to think about
deleting the child widgets.
I hope that someone has an answer for me, because this question is
simply killing me...
Sven Creutz Thomsen