Similar to a class, the structure indicates the data structure that can contain data members and function members.
Different from the class,The structure is value type and does not require heap allocation.
Structure Type VariablesDirectly include structured data,Variables of the class type include references to data.(This variable is called an object ).
The struct type is applicable to lightweight objects such as dots, rectangles, and colors. Although a vertex may be represented as a class,
However, the structure is more effective in some schemes. In some cases, the structure cost is low.
For example, if an array containing 1000 vertex objects is declared, additional memory will be allocated to each referenced object.
The structure can declare constructors, but they must contain parameters.
The default (No parameter) constructor of the declared structure is incorrect.
The default constructor is always provided to initialize the structure members as their default values.
It is incorrect to initialize the instance field in the structure. The instance object must be initialized in the class.
When you use the new operator to create a structure object, this structure object is created and an appropriate constructor is called.
Different from the class, the new operator can be used for structure instantiation. If new is not used, the field remains unassigned and the object is unavailable before all fields are initialized.
For structures, there is no inheritance like classes. A structure cannot inherit from another structure or class, and cannot be the base of a class.
However, the structure inherits from the base class object. The structure can implement interfaces in the same way.