title: Can bit fields be used in C++ classes?
body: <p>In C structs, it is possible to specify another bit length than the default bit length of the type like this:</p>
  
  <pre><code>struct MyStruct{
      int myVar : 1;    //Size of myVar is 1 bit (so it can take values 0 or 1
      int myOtherVar: 4;    //Size of myOtherVar is 4 bits (so it can take values 0 to 15)
  }
  </code></pre>
  
  <p>This is called bit fields.</p>
  
  <p>My question is if it is also possible to do this in C++ classes, like this:</p>
  
  <pre><code>class MyClass{
      public:
          //Some methods
      private:
          int m_myAttribute : 1;
          int m_myOtherAttribute : 4;
  }
  </code></pre>
  
  <p>I searched the web for this but all the examples I found of bit fields used structs, not classes.</p>
  
  <p>I tested this code and it compiled just fine, but I would like to know if the size of the attributes are really the specified size or if the compiler just ignored the bit fields and used the standard <code>int</code> size.</p>