Friday, 13 September 2013

Initializing static global constants with enum value. Is this safe? Pitfalls?

Initializing static global constants with enum value. Is this safe? Pitfalls?

If you want to wrap some enum type with a class, e.g., to build some
functions around it, you could end up with the following situation:
main.cpp:
#include "WrappedEnumConstants.h"
int main(int argc, char * argv[])
{
WrappedZero.print();
WrappedOne.print();
}
WrappedEnumConstants.h
#ifndef WRAPEDENUMCONSTANTS_H
#define WRAPEDENUMCONSTANTS_H
#include "WrappedEnum.h"
#include "InternalEnum.h"
static const WrappedEnum WrappedZero(ZeroEnum);
static const WrappedEnum WrappedOne(OneEnum);

No comments:

Post a Comment