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?
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?
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.
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!"
{
}
};
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).