Union declaration
From cppreference.com
This section is incomplete |
A union is a special class type that stores all of its data members in the same memory location.
Unions cannot have virtual functions and cannot be inherited.
(until C++11) Unions can only contain POD (plain old data) types.
(since C++11) Unions can contains non-trivial types provided that eventual non-trivial constructors are defined by the user.
[edit] Syntax
union name { member_declarations } object_list (optional) ; | (1) | ||||||||
union { member_declarations } object_list ; | (2) | ||||||||
[edit] Explanation
This section is incomplete |
- Named union
- Unnamed union
[edit] Example
Output:
as int: 1024 as char: 128
(for little-endian processors)