1. First of all, I have learned a little bit about it.
Class A is a reference type. Functions can be automatically constructed by default.
The B structure is a value type, and all value types are based on the structure type. The default constructor cannot be used automatically.
When comparing C classes and structures, they both compare their references. But why do we think they are the same or different value types, this is because tcompare is an interface first for value types. In this way, even if the two value types have different address spaces, they will not be considered to be the same, but the same. They should be implemented by the two interfaces. What is the other interface, have time to study.
A simple syntax is supported for the initial values of fields. Classes are supported, but structures are not supported.
Struct structstu {int I; // int I = 5. Why is this writing incorrect? struct cannot customize the default constructor. Int J; Public structstu (int ii) {I = II; // The constructor must Initialize all variables. J = II; // if this line of code does not exist, it is also incorrect .} }
D. When should I use the structure?
Similar to a simple value type. All simple value types are based on the structure type.
The size of the data member is 16 kb. Because the memory of the structure is allocated on the stack, if frequently used, data will be copied in large quantities.
No special initialization operation is required. This is because the structure does not provide Default constructors.
The F structure is a lightweight data encapsulation structure.
My doubts:
What is the difference between allocating structures to stacks and allocating them to stacks?
Stack is allocated by the system, and the original stack is advanced. The address is continuous and efficient.
The heap is allocated by programmers. The address is not consecutive and the efficiency is slow.
To sum up, the structure is a special type. If you do not understand it clearly, it will be used less. Otherwise, it will cause a great waste of program resources and low computing efficiency.
I have time to write a schema topic!