I maintain a large code base and use a combination of forward declarations and the pImpl idiom to save compilation time and reduce dependencies (and this works very well)
I have a problem with classes that contain public enumerations. These enumerations cannot be declared forward, so I am left with no option, but to include the class header. For instance:
// Foo.h class Foo { public: enum Type { TYPE_A, TYPE_B, }; ... }; // Bar.h #include "Foo.h" // For Foo::Type class Bar { public: void someFunction(Foo::Type type); ... };
So, I am looking for ways to avoid this and can only think of the following:
Move class enumerations to a separate type namespace
// FooTypes.h namespace FooTypes { enum Type { TYPE_A, TYPE_B, }; } // Bar.h
Use int instead of listing
// Bar.h class Bar { public: void someFunction(int type); ... };
What did I miss? How other people will manage this restriction (not being able to forward the declaration of transfers.)
source share