enum constant members

Q

qazmlp

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
} ;
} ;
 
C

Chris \( Val \)

| 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
 
R

Ron Natalie

qazmlp said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top