title: How to use enums as flags in C++?
body: <p>Treating <code>enum</code>s as flags works nicely in C# via the <code>[Flags]</code> attribute, but what's the best way to do this in C++?</p>
  
  <p>For example, I'd like to write:</p>
  
  <pre><code>enum AnimalFlags
  {
      HasClaws = 1,
      CanFly =2,
      EatsFish = 4,
      Endangered = 8
  };
  
  seahawk.flags = CanFly | EatsFish | Endangered;
  </code></pre>
  
  <p>However, I get compiler errors regarding <code>int</code>/<code>enum</code> conversions.  Is there a nicer way to express this than just blunt casting?  Preferably, I don't want to rely on constructs from 3rd party libraries such as boost or Qt.</p>
  
  <p>EDIT: As indicated in the answers, I can avoid the compiler error by declaring <code>seahawk.flags</code> as <code>int</code>.  However, I'd like to have some mechanism to enforce type safety, so someone can't write <code>seahawk.flags = HasMaximizeButton</code>.</p>