It is well known that in C++ struct
Derived from the historical legacy of the C language, except that the default scope is public
outside, with class
There is no difference, in theory they can be mixed. We use the standard library and engineering practices such as Unreal to implement struct
和 class
Make a summary of keyword selection.
- If the type contains something other than
public
Member variables should be selectedclass
. - If the type contains
virtual
function, should be selectedclass
. - If the type can Aggregation initialization , should be considered
struct
. - If the constructor, destructor and assignment function of the type are
= default;
implementation, should be consideredstruct
.