1, the initialization of the struct can use an array-like way, as follows:
struct Student
{
int _age;
string _name;
};
Student stu = {+, "Andy"};
2. There are two places to be aware of:
A, the order should be consistent, as follows:
Student stu = {"Andy", 26}; Compile error
B, the following can not be initialized
Student stu = {26}; Initialize _age only
3, consider the following situation, student there is a field, indicating the size of the student object, and in the debug and release, the size is not the same, how to do?
Use sizeof as follows:
struct Student
{
Int_size;
int _age;
string _name;
};
Student stu = {sizeof (stu), +, "Andy"};
4, note: The same data type, in Debug and release mode, the memory may be different. Like what:
Int:debug and release are all 4 bytes.
String:debug occupies 32 bytes, release occupies 28 bytes
5, in the debug mode, the object itself may occupy some more bytes, while in debug mode, the object will also occupy a number of bytes (such as int before and after the 4 bytes), for saving debugging information.
Initialization of a struct