lundi 9 novembre 2020

Generate a enum based on a constant value in C++

Is it possible to create a enum based on a constant in C++ ?

If my constant value is 5, i want the enumerator to have 5 elements like below

typedef enum {
LIC_0,
LIC_1,
LIC_2,
LIC_3,
LIC4,
} licfiles_t;

If my constant value is 10, i want the enumerator to be like this instead,

typedef enum {
LIC_0,
LIC_1,
LIC_2,
LIC_3,
LIC4,
LIC5,
LIC6,
LIC7,
LIC8,
LIC9,
} licfiles_t;

The reason i want this is , i have a constant called "MaxLicenses" defined to be 30 now and have a corresponding enumerator that has 30 enum values in it. If someone changes "MaxLicenses" to 20 instead, they shouldn't have to bother changing the enumerator as well. That is my fundamental idea.

Aucun commentaire:

Enregistrer un commentaire