By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Enumerations as case labels

P: n/a
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?
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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?


It seems that the line

case I<D>::E:

should only work inside the class member function (since there probably
no 'D' outside, although, who know?). However, your class template has
no member functions. Care to post a complete example?

V
Jul 23 '05 #2

P: n/a
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?


template <> class I<int>
{ // explicit specializatino
};

surprise: no E!

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #3

P: n/a

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)

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.