- The default access for the class is
private
(and for the structure is public
). Thus, color
declared as private
. - In lines 14-20, the
Point
structure is internal for the class Figure
. It is in the public
, so it is “visible” outside. This is only a declaration of the Point
structure, but not a declaration of the field of type Point
. (There is no such field in the structure.) You can use this type, for example, by declaring variables of this type: Figure::Point point;
. - Lines 8-10 show the implementation of the constructor, typical of C ++.
Let's write down the lines:
Figure(int color) : // Конструктор принимает один параметр. color(color) // Инициализация полей: для поля color вызывается конструктор // с аргументом, равным аргументу color из конструктора. По // стечению обстоятельств, их имена одинаковы. {} // Больше конструктор ничего не делает. // Это типично для конструкторов в C++: только инициализировать // поля и всё.
The constructor at Point
executed in the same key, only it initializes 2 fields.
In the constructor, you can also initialize the base classes in addition to the fields directly before the constructor body. But Figure
/ Point
does not have a base class, so this part disappears. If there are base classes, and you have not registered an initializer, the constructor of the base class with no parameters will be called (well, or one that can be called without parameters).