473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Enumerations as case labels

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
3 1668
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Anderson | last post by:
Is this sort of thing possible: var X = 'Moe'; switch (X) { case 'Curly'||'Moe'||'Larry': alert('Found one of the Three Stooges'); case 'Chico'||'Harpo'||'Zeppo'||'Grouco'||'Gummo':...
55
by: aarklon | last post by:
Hi, why general integer expressions are not allowed in case labels in switch statements..????
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.