I have my error codes (about 30 error codes) stored in an enum. A collegue warned me about it because if I change the numerical value of an enum, all code which uses my DLL will have to recompile or else the error codes become inconsistent. I understand the problem: enums become integer constants during the compile process, so the DLL uses the enum values which were valid at compile time, not at runtime as I would prefer.
My question is how I can do better. Please help me. In the following, I explain an idea of mine, but better ideas are welcome if my idea has severe disadvantages.
My first idea is to make a class and store the codes as static constant members
class ErrorCodes
{
public:
static const int ok;
static const int error1;
static const int error2;
};
and define their values in the .cpp
const int ErrorCodes:ok = 0;
const int ErrorCodes:error1 = -1;
const int ErrorCodes:error2 = -2;
Does this fix the above problem? What happens if I add or remove members? What happens if I change the values of the error codes?