lundi 27 janvier 2020

How to declare enums as extern with default values

I want to create an enum in C++11 such a way that the I can declare some constants value in a source code while declaring them in header file:

A.hpp

typedef enum class ABC: uint8_t
{
    CAR,
    DOG,
    HOUSE
};
extern ABC ABCType;

A.cpp

#include "A.hpp"

ABCType = { CAR = 1, DOG = 2, HOUSE = 3 };

The reason to do that the values that the enumerators initial values depends on some other library declarations and needs to be non modifiable by users [just a coding style requirement for me]. So user can use something like below:

#include "A.hpp"

int classA::method()
{
....................
check(ABCType.HOUSE);
....................
}

I tried this way but VC IDE says "too many initializer value" ?

Aucun commentaire:

Enregistrer un commentaire