[White] road to learning C ++ structures and unions

  • Structure struct

C ++ syntax, not only the structure can have its own data members, can also have its own function member, with its own constructor, destructor, access control, inheritance, polymorphism comprising the like. The syntax is almost the same.

This is an extension to the C Struct, mainly because in order to retain compatibility with C's.

Purpose: define data types, the combination as a whole, but there is no operation for the structure.

Initial value:

Variable name type name = {1 Initial data members, member of the initial value data 2, ......}

 

 

Difference: the default access control permissions struct is public, the class is private.

 

 

  • Commonwealth union

The same point: Commonwealth class is a special form, can have its own data members, member functions, has its own constructor, destructor, access control (the same public default), also inherited from the C language .

Differences: all data members of the Commonwealth of union share the same set of memory cells. So the Commonwealth of internal variables at most only one meaningful.

              Commonwealth does not support inheritance, polymorphism is not supported.

 

Guess you like

Origin www.cnblogs.com/ACStrive/p/11610120.html