[SOVLED] Puzzling class member and its usage in class constructor
I inherited a piece of code as the following:
In the header file:
class MainWindow : public QMainWindow
explicit MainWindow(QWidget *parent = 0);
In cpp file, the class constructor as defined as below:
MainWindow::MainWindow(QWidget *parent) :
Question is why a pointer to itself in the header file? Is this not just "this" as in C++?
Then in the constructor, ui(new Ui::MainWindow) is used in the constructor. What does it do to the constructor?
Hi and welcome to devnet,
'ui' is not an instance of the MainWindow class but of the Ui::MainWindow one that is defined inside the namespace Ui.
@mcosta Thank you. Indeed I found the class definition for Ui::MainWindow. So the constructor initializes the member class *ui using ui(new Ui::MainWindow).