0
Child::Child()
: Parent(NTPoint(250.f, 250.f))
, angle(0.f)
, lastAction(10.f)
{
}

What I'm not understanding the function of is the commas followed by variable names after the parent bit. Can anyone help?

Leon
  • 43
  • 5
  • You're initializing variable `a` and variable `lastAction` with those values. It's called _initialization list_ and it's usually preferred (see [this post](http://stackoverflow.com/questions/6822422/c-where-to-initialize-variables-in-constructor)). – Adriano Repetti May 14 '14 at 14:16

3 Answers3

1

That is not a function declaration. This is a constructor declaration, and this is called constructor initializer list. Commas just separate members to initialize.

Note: should not be confused with initializer list.

luk32
  • 15,812
  • 38
  • 62
0

It's the initializer-list syntax to separate the initializing items in the constructor of a class.

class A
{
   int x;
   int y;
   std::string z;

public:
   A::A() :          // Colon starts the initializer-list
          x(0),      // variable x is set to 0
          y(1),      // variable y is set to 1
          z("Hi!")   // string   z is set to "Hi!"
  {
  }
};
masoud
  • 55,379
  • 16
  • 141
  • 208
0

It is indeed a constructor initializer list. It defines the default constructor as there are no parameters in child. Furthermore it initializes data members. As an example the data member lastAction is being initialized with the value 10 (float).

Seyon
  • 481
  • 6
  • 13