title: What is the best way to initialize a bitfield struct in C++?
body: <p>In C++, I have a class which contains an anonymous bitfield struct.  I want to initialize it to zero without having to manually write out all fields.</p>
  
  <p>I can imagine putting the initialization in three places:</p>
  
  <ol>
  <li>Create a constructor in the bitfield</li>
  <li>Zero out in the initializer list of the constructor for the containing class</li>
  <li>Zero out in the body of the constructor for the containing class</li>
  </ol>
  
  <p>This bitfield has many fields, and I'd rather not list them all.</p>
  
  <p>For example see the following code:</p>
  
  <pre><code>class Big {
      public:
          Big();
  
          // Bitfield struct
          struct bflag_struct {
              unsigned int field1 : 1;
              unsigned int field2 : 2;
              unsigned int field3 : 1;
              // ...
              unsigned int field20 : 1;
              // bflag_struct(); &lt;--- Here?
          } bflag;
  
          unsigned int integer_member;
          Big         *pointer_member;
  }
  
  Big::Big()
    : bflag(),             // &lt;--- Can I zero bflag here?
      integer_member(0),
      pointer_member(NULL)
  {
      // Or here?
  }
  </code></pre>
  
  <p>Is one of these preferable? Or is there something else I'm missing?</p>
  
  <p>Edit: Based on the accepted answer below (by Ferruccio) I settled on this solution:</p>
  
  <pre><code>class Big {
      // ...
  
      struct bflag_struct {
          unsigned int field 1 : 1;
          // ...
          bflag_struct() { memset(this, 0, sizeof *this); };
      }
  
      // ...
  }
  </code></pre>