er initializer lists ](/w/cpp/language/constructor
"cpp/language/constructor")  
[ Default member initializer
](/w/cpp/language/data_members#Member_initialization "cpp/language/data
members") (C++11)  
[ ` friend ` specifier ](/w/cpp/language/friend "cpp/language/friend")  
[ ` explicit ` specifier ](/w/cpp/language/explicit "cpp/language/explicit")  
[ Converting constructor ](/w/cpp/language/converting_constructor
"cpp/language/converting constructor")  
Special member functions  
[ Default constructor ](/w/cpp/language/default_constructor
"cpp/language/default constructor")  
[ Copy constructor ](/w/cpp/language/copy_constructor "cpp/language/copy
constructor")  
[ Move constructor ](/w/cpp/language/move_constructor "cpp/language/move
constructor") (C++11)  
[ Copy assignment operator ](/w/cpp/language/copy_assignment
"cpp/language/copy assignment")  
[ Move assignment operator ](/w/cpp/language/move_assignment
"cpp/language/move assignment") (C++11)  
[ Destructor ](/w/cpp/language/destructor "cpp/language/destructor")  
Inheritance  
[ Base and derived classes ](/w/cpp/language/derived_class
"cpp/language/derived class")  
[ Empty base optimization (EBO) ](/w/cpp/language/ebo "cpp/language/ebo")  
[ Virtual member functions ](/w/cpp/language/virtual "cpp/language/virtual")  
[ Pure virtual functions and abstract classes ](/w/cpp/language/abstract_class
"cpp/language/abstract class")  
[ ` override ` specifier ](/w/cpp/language/override "cpp/language/override")
(C++11)  
[ ` final ` specifier ](/w/cpp/language/final "cpp/language/final") (C++11)  
  
[ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/language/classes/navbar_content&action=edit)

Declares a class data member with explicit size, in bits. Adjacent bit-field
members may (or may not) be packed to share and straddle the individual bytes.

A bit-field declaration is a [ class data member declaration
](/w/cpp/language/data_members "cpp/language/data members") which uses the
following declarator:  
  
---  
identifier  ﻿  (optional)  attr  ﻿  (optional)  ` **:** ` size  |  (1)  |   
identifier  ﻿  (optional)  attr  ﻿  (optional)  ` **:** ` size  brace-or-equal-initializer  |  (2)  |  (since C++20)   
  
The _type_ of the bit-field is introduced by the  decl-specifier-seq  of the [
declaration syntax ](/w/cpp/language/declarations "cpp/language/declarations")
.

attr  |  \-  |  (since C++11)  sequence of any number of [ attributes ](/w/cpp/language/attributes "cpp/language/attributes")  
---|---|---  
identifier  |  \-  |  the name of the bit-field that is being declared. The name is optional: unnamed bit-fields introduce the specified number of [ padding bits ](/w/cpp/language/object#Object_representation_and_value_representation "cpp/language/object") .   
size  |  \-  |  an [ integral constant expression ](/w/cpp/language/constant_expression#Integral_constant_expression "cpp/language/constant expression") with a value greater or equal to zero. When greater than zero, this is the number of bits that this bit-field will occupy. The value zero is only allowed for nameless bit-fields and has  special meaning  .   
brace-or-equal-initializer  |  \-  |  [ default member initializer ](/w/cpp/language/data_members#Member_initialization "cpp/language/data members") to be used with this bit-field   
  
##  Contents

  * 1  Explanation 
  * 2  Notes 
  * 3  Defect reports 
  * 4  References 
  * 5  See also 

  
---  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/language/bit_field&action=edit&section=1 "Edit
section: Explanation") ]  Explanation

The type of a bit-field can only be integral or (possibly cv-qualified)
enumeration type, an unnamed bit-field cannot be declared with a cv-qualified
type.

A bit-field cannot be a [ static data member ](/w/cpp/language/static
"cpp/language/static") .

There are no bit-field [ prvalues ](/w/cpp/language/value_category
"cpp/language/value category") : lvalue-to-rvalue conversion always produces
an object of t