Results 1 to 5 of 5

Thread: Puzzling class member and its usage in class constructor

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2015
    Posts
    2

    Post Puzzling class member and its usage in class constructor

    I inherited a piece of code as the following:

    In the header file:

    namespace Ui
    {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    ...
    }

    In cpp file, the class constructor as defined as below:
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)

    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?
    Last edited by Karen; 15th June 2015 at 18:56.

Similar Threads

  1. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  2. Replies: 4
    Last Post: 29th May 2010, 12:56
  3. class constructor
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2008, 18:25
  4. default parameters in constructor class
    By mickey in forum General Programming
    Replies: 4
    Last Post: 23rd February 2008, 18:44
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.