2

Possible Duplicate:
What does a colon following a C++ constructor name do?

I am finding this syntax strange in C++

TagDetails::TagDetails(QWidget *parent) :
QDialog(parent),
ui(new Ui::TagDetails)

This is declaration of constructor in C++... What does the thing after colon stand for, i.e. what does ui(new Ui::TagDetails) mean here? What is the colon for?

Community
  • 1
  • 1
chai
  • 1,385
  • 5
  • 20
  • 30

3 Answers3

5

It is a member initialization list.

ui(new Ui::TagDetails) means that the member variable ui is initialized with the pointer to newly allocated object of type Ui::TagDetails.

vitaut
  • 43,200
  • 23
  • 168
  • 291
1

What you're looking at is an initializer list. The ui member of the class is being initialized with a value of new Ui::TagDetails, where TagDetails is defined inside the class or namespace Ui.

Mark Ransom
  • 286,393
  • 40
  • 379
  • 604
0

This is called an initialization list. See C++ FAQ for the pros of initialization lists over assignment.

I'm not familiar with the site, but this page seems to explain quite thoroughly how things work.

icecrime
  • 71,079
  • 13
  • 98
  • 110