Martin Magnusson wrote:
I'm using enums as case labels throughout my code, and that works fine
in gcc 3.3.4. However, when compiling it with the compiler that ships
with Dev-C++ 4.9.8.0, I get the error "case label does not reduce to an
integer constant".
The case label in question looks like this
case I<D>::E:
And I have a class
template <unsigned D>
class I
{
public:
enum M {A,B,C,D,E};
};
Shouldn't that work?
unless i'm mistaken it should not. you are using D for both the template
parameter and the enum member name. if you want that 4th enum member to
equal D, you should do:
template <unsigned N>
class I
{
public:
enum M { A, B, C, D = N, E };
};
secondly, as others have pointed out unless there is another D, you
can't access D outside of the template. this should work:
case I<42>::E:
or maybe:
int const D = 42;
case I<D>::E:
i'm not sure what you're trying to do, but if you want to use the D enum
member as the template parameter, you can't do it quite like that. you
could follow the example of ios in the stl and do:
class I_base
{
public:
enum M { A, B, C, D, E };
};
template <unsigned N>
class I :
public I_base
{
public:
};
and then you could do:
case I<I_base::D>::E:
if that's what you're looking for.
--
Mark A. Gibbs (aka. Indi)
Administrator
#c++ on irc.Rizon.net
http://ca.geocities.com/in***@rogers.com/
(temporary website)