[Insight-developers] Re: Borland C++ compiler and enums
Brad King
brad.king@kitware.com
Mon, 4 Feb 2002 14:24:46 -0500 (EST)
Hi Jim,
> enum { SpaceDimension = NDimensions,
> ParametersDimension = NDimensions };
[snip]
> Does anyone know a work around for this problem?
We can use a static const int instead of an enum on some platforms. In
fact, I have now come to the conclusion that a static const int is the
CORRECT choice, and that an enum should be used as a workaround.
Standard C++ allows in-class static member initialization for const
integral types:
struct Foo
{
static const int bar = 1;
};
Most compilers support this, but those that don't seem to support the enum
as we are currently using. The boost libraries use a macro like this:
struct Foo
{
ITK_STATIC_CONSTANT(int, bar = 1);
};
On conforming compilers, the macro is defined like this:
#define ITK_STATIC_CONSTANT(type, assignment) static const type assignment
on other compilers, it is defined like this:
#define ITK_STATIC_CONSTANT(type, assignment) enum { assignment }
This should allow transparent usage of the constants for most purposes.
-Brad