[SOLVED] What's the stuff after the colon mean on this function definition?



  • Newbie here. In the snippet below, what's the stuff after the single colon mean? Coming from the PHP world, I understand what the :: means, but not the single colon in this context:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
    /snip
    

    The part I'm talking about begins with QMainWindow...



  • This is basic C++: the MainWindow::MainWindow(QWidget *parent) is the declaration of the MainWindow constructor as you've probably guessed, and MainWindow class inherits from QMainWindow. The part between the colon and the opening brace is the member initialiser list: it actually calls the constructor of the mother class and of the members.
    Whilst the members can be initialised in the constructor body, the mother class cannot, therefore it is the mandatory part of this `stuff'. The mother class constructor must be the first called constructor in that section. Then using this mechanism to initialise class members or do it in the constructor itself is kind of up to you.



  • Since it's a comma-delimited list, can I assume that it inherits from both QMainWindow and the ui class too?



  • @maximo said:

    Since it's a comma-delimited list, can I assume that it inherits from both QMainWindow and the ui class too?

    ui is probably a member.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.