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,483
  • 5
  • 21
  • 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
  • 49,672
  • 25
  • 199
  • 336
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
  • 299,747
  • 42
  • 398
  • 622
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
  • 74,451
  • 13
  • 99
  • 111