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

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


Just checked this...

The problem is typedef for Point cannot access SpaceDimension.  SpaceDimension needs to be prepended
with a classname.

The Boost pages suggest using a traits class to propagate these "constants" down
to other classes.  I'd hate to have to wrap every enum definition/access in a 
trait.


-----Original Message-----
From: Miller, James V (CRD) 
Sent: Monday, February 04, 2002 3:06 PM
To: 'Brad King'
Cc: Insight-developers (E-mail)
Subject: [Insight-developers] RE: Borland C++ compiler and enums


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
_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers