[Insight-developers] RE: Borland C++ compiler and enums

Miller, James V (CRD) millerjv@crd.ge.com
Mon, 4 Feb 2002 15:06:27 -0500


We tried this this morning.  The problem was in passing SpaceDimension
down into another template class, you had to spec out the entire path
down to enum. So we couldn't just do

  ITK_STATIC_CONST(int, SpaceDimension=NDimension);
  typedef Point<TScalarType, SpaceDimension> InputPointType;

I'll double check this....


-----Original Message-----
From: Brad King [mailto:brad.king@kitware.com]
Sent: Monday, February 04, 2002 2:25 PM
To: Miller, James V (CRD)
Cc: Insight-developers (E-mail)
Subject: Re: Borland C++ compiler and enums


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