Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

C++0x Forward Enum Declarations Cut Down Compilation Time and Dependencies

A new C++0x feature called forward enum declarations allows you to declare an enumeration without providing its enumerators list. Learn how using it can avert long compilation times and ODR violations.


advertisement

very declaration of an enum type must be a complete definition containing a full list of its enumerators. However, in some use cases declaring an enumeration without providing the enumerators list is desirable. For example, you may use a forward declaration like this...

enum class Direction;

...instead of repeating the complete definition (see below) in every translation unit.



enum class Direction: short {Up, Down};

A year ago, the C++ standards committee voted into the Working Draft a proposal to add forward declarations of enum types. This 10-Minute Solution shows how to use forward declarations of enum types to expedite compilation time and reduce code dependencies.


Your project has an enum type containing hundreds of machine-generated enumerators that change frequently. You must provide a complete definition of that enum in every translation unit, even if the compiler seemingly doesn't need the complete definition of the enum.


Replace complete definitions of enum types with forward enum declarations where possible.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap