473,385 Members | 1,351 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,385 software developers and data experts.

enum constant members

What advantage does the following give
class testClass
{
public:
enum Type
{
CONST0= 0 ,
CONST1= 1 ,
CONST2= 2
} ;
} ;

compared to

class testClass
{
public:
enum
{
CONST0= 0 ,
CONST1= 1 ,
CONST2= 2
} ;
} ;
Jul 19 '05 #1
2 2481

"qazmlp" <qa********@rediffmail.com> wrote in message
news:db**************************@posting.google.c om...
| What advantage does the following give
| class testClass
| {
| public:
| enum Type
| {
| CONST0= 0 ,
| CONST1= 1 ,
| CONST2= 2
| } ;
| } ;
|
| compared to
|
| class testClass
| {
| public:
| enum
| {
| CONST0= 0 ,
| CONST1= 1 ,
| CONST2= 2
| } ;
| } ;

Without a type, how would you otherwise do this:

class testClass
{
public:
enum Type
{
CONST0 = 0,
CONST1 = 1,
CONST2 = 2
};

testClass( const Type& e ) {}
};

int main()
{
testClass t( testClass::CONST1 );

return 0;
}

Cheers.
Chris Val
Jul 19 '05 #2

"qazmlp" <qa********@rediffmail.com> wrote in message news:db**************************@posting.google.c om...
What advantage does the following give
class testClass
{
public:
enum Type


The former declares a type, the latter doesn't. What are you going to do with these
constant values? If you need a variable to hold them (and only them), then you're
going to need the type. Otherwise they're just going to be some unspecified integral
value.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
12
by: Steven T. Hatton | last post by:
Any opinions or comments on the following? I don't say it below, but I came out on the side of using enumerations over static constants. /* I'm trying to figure out the pros and cons of using...
3
by: Ozzy Knox | last post by:
I am trying to convert a string or int variable to an Enum that I have set up in my C# application. I have tried many options with no success. Any advice would be appreciated. Regards Ozzy
4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
21
by: Bilgehan.Balban | last post by:
Hi, I have two different enum definitions with members of same name. The compiler complains about duplicate definitions. Is this expected behaviour? Can't I have same-named fields in...
12
by: Laurent Deniau | last post by:
If I understand well, an enumeration is only garantee to hold at most an int (6.7.2.2-2). So I would like to know: how to store a long in an enum? enum { p2_31 = 1L << 31 }; // boom how to...
10
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize...
13
by: toton | last post by:
Hi, I have some enum (enumeration ) defined in some namespace, not inside class. How to use the enum constant's in some other namespace without using the whole namespace. To say in little...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.