title: In C++, how can I avoid #including a header file when I need to use an enumeration?
body: <p>In my C++ header files I try to use forward declarations (class MyClass;) instead of #including the class header, as recommended in many C++ coding standards (the Google C++ Style Guide is one).</p>
  
  <p>Unfortunately, when I introduce enumerations, I can't do the forward declaration any more. Like this:</p>
  
  <pre><code>//// myclass1.hpp ////
  
  class MyClass1
  {
      enum MyEnum1
      {
          Enum_A, Enum_B, Enum_C
      };
  };
  
  //// myclass2.hpp ////
  
  // I want to avoid this
  #include "myclass1.hpp"
  
  // I'd prefer to do this (forward declaration)
  class MyClass1;
  
  class MyClass2
  {
      // This is o.k.: I only need to forward declare MyClass1
      MyClass1* ptr;
  
      // This forces me to #include, but I don't want to!
      void func( MyClass1::MyEnum1 e );
  };
  </code></pre>
  
  <p>The best solution I can think of so far is to replace enums with member constants:</p>
  
  <pre><code>//// myclass1.hpp  ////
  
  MyClass1
  {
      static const int Enum_A;
      static const int Enum_B;
      static const int Enum_C;
  };
  
  //// myclass1.cpp ////
  
  const int Enum_A = 1;
  const int Enum_B = 2;
  const int Enum_C = 3;
  </code></pre>
  
  <p>In this case, though, the solution seems worse than the problem.</p>
  
  <p>I'm currently looking through <em>Large Scale C++ Software Design</em> (Lakos) and <em>Working Effectively with Legacy Code</em> (Feathers) for dependency breaking techniques, but I haven't found a good solution yet.</p>