billcoke
billcoke

Reputation: 770

abstracting c++ enums to reduce compilation

In my code I have a central data storage that is referenced into via enumerated symbols. This allows me to see all the places in my code where the enum'd symbol is referenced for setting/getting a value. The problem comes in whenever I want to add a new symbol it requires that all of the code that might access the data storage be recompiled because all of it touches the enum header file.

Is there some abstract that would reduce recompiles? Maybe a design pattern?

Upvotes: 1

Views: 152

Answers (2)

BЈовић
BЈовић

Reputation: 64223

Only thing you can do is to use strongly typed enums, if you have access to c++11 features. Then you can forward declare the enum, and you do not have to include that header in other headers needing the enum.

For pre-c++11, nothing can be done to prevent the recompilation.

Upvotes: 1

PherricOxide
PherricOxide

Reputation: 15919

That's the problem you have with a "central data storage" as you called it. That sounds like an excuse for putting all of the enums you don't know what to do with in a single header file.

If an enum is related to a class and used only when that class is used, put it in the same header file as the class. If your enums are really all stand alone, you can still divide that header file into multiple header files that have more specific categories of enums in them.

Upvotes: 1

Related Questions