Author: Vitaly Buturlin
Content:
Trivial class
Trivial classes ( The trivial class ) - is a class or structure in which the special member functions provided by the compiler (obviously there is no implementation) or explicitly defined as a default. There is no control code in such a class , since the special member functions are declared (explicitly or implicitly) trivial by default.
In addition, there are additional requirements, the trivial class must not have:
virtual functions
non-trivial base classes
non-trivial data types
The word "trivial" means the presence of:
trivial special member functions ( msdn )
Members POD (see below)
Trivial classes can be safely copied with functions like memcpy in full precision.
Triviality of member functions (lack of control code) implies:
memory allocation for an object without initialization
byte copying of an object
freeing memory without cleaning
Standard layout
Standard structure ( standard layout ) - a structure (struct), which contains accessibility C ++:
virtual functions and virtual base classes
several levels of access (private, protected)
non-static members of a reference type
Standard structure:
has no members that are non-standard structure
has no base classes other than non-standard structure
does not have more than one base class with non-static data members
does not have two places for declaring non-static members (for example, in the base class and in itself)
does not have more than two base (or indirectly) classes
The standard structure has a predictable memory structure , since it does not contain data that the compiler could structure at its own discretion (for example, in the case of public / private / protected) - both written and stored in memory .
Author: Vitaly Buturlin