I am trying to create an error enum and associated text descriptors aligned in the same file. I have a system.cpp file that contains the following:
#define SYSTEMCODE
#include "myerrors.h"
The file myerrors.h contains:
typedef enum errors {
OK,
BADERROR,
LASTENUM } ERR;
#ifndef SYSTEMCODE
extern char const *_errtext[];
#else
const char * _errtext[ERR::LASTENUM +1] = {
"OK",
"BADERROR",
"LASTENUM" };
#undef SYSTEMCODE
#endif
I include system.h in all sources that need error services and they do not define SYSTEMCODE.
I expect that only the system.cpp file will compile the text array and all others will simply have an extern reference. The system.cpp object does not have the _errtext array thus causing a link error. I disable pre-compiled headers and I have tried many variations of this. MSDEV does not get it right.
Any ideas?