Search code examples
c++wt

Derived Class Constructor Syntax Wt


Hello fellow C++Programmers,

today I was tinkering around with the excellent Wt framework Wt - a C++ library for developing web applications: http://www.webtoolkit.eu/wt.

Slowly but steadily I'm making progress. One thing that made me curious is (I'm pretty new to C++) the following expression in the constructor of a class derived from the basic Wt::WContainerWidget class:

class FooWidget : public Wt::WContainerWidget
{
  public:
  FooWidget(Wt::WContainerWidget *parent = 0);
  ...

  private:
  ...
};

FooWidget::FooWidget(Wt::WContainerWidget *parent = 0)
: Wt::WContainerWidget(parent)
{
  ...
};

Note: In Wt all the widgets are placed in a hierarchical tree so the optional parent argument specifies the widget that will contain our "newborn" widget.

What is happening in the ": Wt::WContainerWidget(parent)" part? I know that the expressions behind the ":" in a constructor are used to initialize member variables but this doesn't seem to make sense here because it's just a class name, not the name of a member ... am I missing something important?

Many thanks in advance and regards,

Julian


Solution

  • This part of the initialization list:

    : Wt::WContainerWidget(parent)
    

    it calling the base class(Wt::WContainerWidget) constructor with the argument parent. You can read this thread for more details.