1 typedef Union para2 {3 Doubletmp[Ten];4 struct5 {6 DoubleA;7 Doubleb;8 DoubleC;9 DoubleD;Ten }NP; One }npara; A //or as shown below - Union para - { the Doubletmp[Ten]; - struct - { - DoubleA; + Doubleb; - DoubleC; + DoubleD; A }NP; at }; - typedef Union para Npara; - - //See the use of typedef in detail, this article mainly explains the use of Union, not to repeat
Use of Union unions:
For example, after using a TypeDef, we can declare a union object like this
Npara Nlpara; Call can be used when the NLPARA.NP.A;
Or declare a union pointer,
Npara *pointer;//But only a pointer is declared, the pointer is not initialized, there is no point to the determined object, and the debug code has a pointer error.
So to initialize the pointer, you can do this in C + +:
Pointer=new npara;//Even if the new Union object is assigned to the current pointer,
We know that new and delete are generally interdependent, and at the end of the program, you can use
if (Null!=pointer)
{
Delete pointer;
Pointer=null;
}
In addition, if you create a new pointer object in the constructor, delete it from the destructor.
Use of the Union (Union) in C + +