Help me understand C++ constructor syntax
-
APPEND
I am not sure if this is a good idea - adding to older post , so I may copy it into a new post .
I am again at lost analyzing this syntax.
I have some udersting of the "new" entried, but I do not get this part
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),Would it be possible to get an expiation in English ?
I am trying to convert QMainWindow class to QWidget.
//! [0] MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), m_status(new QLabel), m_console(new Console), m_settings(new SettingsDialog), //! [1] m_serial(new QSerialPort(this)) //! [1]
DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent)
: QDialog(parent), localDevice(new QBluetoothLocalDevice),
ui(new Ui_DeviceDiscovery)
{Where would be a good resource to learn this?
I actually need to get info on "localDevice" , and have never used C++ this way.
Actually this complex constructor is used by passing null pointer , or better - passing default NULL pointer
as QWidget *parent). Little too complex for me...If it is OK - I could probably get started if somebody reads me the code in English...
Thanks
-
// Create an instance of DeviceDiscoveryDialog // and pass a "parent" parameter of type QWidget* to the constructor DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent) // Call the constructor of base class QDialog and pass the "parent" parameter to it : QDialog(parent), // dynamically allocate an instance of class QBluetoothLocalDevice // initialize member DeviceDiscoveryDialog::localDevice using that instance localDevice(new QBluetoothLocalDevice), // dynamically create an instance of class Ui_DeviceDiscovery // initialize member DeviceDiscoveryDialog::ui using that instance ui(new Ui_DeviceDiscovery)
Where would be a good resource to learn this?
Probably any C++ book e.g. "A Tour of C++".
If you prefer online resource cppreference page about constructors is a good place to start. -
I would like to throw this page into the ring which explains member initializer lists from the beginning.
-
Thank you very much for replies. Appreciate the help.
I think I asked this before - would "allocate an instance of class" be same as " build an object of class " ?
-
I would like to throw this page into the ring which explains member initializer lists from the beginning.
@DerReisende This is also "correct answer
. Thanks. -
Thank you very much for replies. Appreciate the help.
I think I asked this before - would "allocate an instance of class" be same as " build an object of class " ?
@AnneRanch said:
would "allocate an instance of class" be same as " build an object of class "
Yes