Rectangle(Point2D center, double w, double h, double r, double g, double b):center(center)
{
...
}
What does the :center(center)
part of this code do?
Rectangle(Point2D center, double w, double h, double r, double g, double b):center(center)
{
...
}
What does the :center(center)
part of this code do?
:
initializes center
member with center
parameter.
In most case (not always!) your code
Rectangle(Point2D center, double w, double h, double r, double g, double b):center(center)
{
....
}
could be replaced with
Rectangle(Point2D center, double w, double h, double r, double g, double b)
{
this->center = center;
....
}
You can read more about initialization lists in C++ here
It's used to initialize the element . Since C++ is object oriented everything is treated as object even datatypes. so when you use initialization list the object are initialized when the object is created for it.
This is considered to better(faster) way then assigning to the variable directly.
As definition and declaration happens in one go.