enum constant members

Discussion in 'C++' started by qazmlp, Jul 8, 2003.

  1. qazmlp

    qazmlp Guest

    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
    } ;
    } ;
    qazmlp, Jul 8, 2003
    #1
    1. Advertising

  2. "qazmlp" <> wrote in message
    news:...
    | 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
    Chris \( Val \), Jul 8, 2003
    #2
    1. Advertising

  3. qazmlp

    Ron Natalie Guest

    "qazmlp" <> wrote in message news:...
    > 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.
    Ron Natalie, Jul 8, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    515
  2. Jerminia
    Replies:
    3
    Views:
    606
    Roedy Green
    Oct 7, 2005
  3. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    435
    Rolf Magnus
    Nov 13, 2003
  4. mrhicks
    Replies:
    2
    Views:
    391
    Dave Thompson
    Jun 10, 2004
  5. Randy
    Replies:
    1
    Views:
    506
    David Harmon
    Jan 7, 2006
Loading...

Share This Page