Thread: hi, explanation for this.., using enum and the scope resolution..., ?

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    142

    hi, explanation for this.., using enum and the scope resolution..., ?

    anyway this is what happened,

    Code:
    enum WHATSHAPE { TRIANGLE, SQUARE, CUBE };
    
    class SHAPE
    {
    enum SHAPETYPE { DEFAULT, CUBE }m_ShapeType;
    }
    now i made a member function for the shape class, here is the definition

    Code:
    void CreateShape(WHATSHAPE shape)
    {
         switch (shape)
         {
         case TRIANGLE:
              break;
         case SQUARE;
              break;
         case CUBE: // error, will say that cube is already used, ie it's value is 1;
             break;
     }
    so the solution to that is, to make my case CUBE: like this instead,
    case WHATSHAPE::CUBE, and this would work out well.,

    and my question is this, how come this doesn't want to work?
    case WHATSHAPE::SQUARE and case WHATSHAPE::TRIANGLE, i would have to modify my

    enum SHAPETYPE and add these two constant value for that to work?


    thanks a bunch!

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    switch (shape)
    {
    case TRIANGLE:
    break;
    case SQUARE;
    break;
    case CUBE: // error, will say that cube is already used, ie it's value is 1;
    break;


    look at the second case, that would be a : after SQUARE not a ;
    changing that will probably fix your error

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    ei no, that's just a type,

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Try
    case WHATSHAPE::CUBE

    or
    case SHAPETYPE::CUBE

    You have two CUBE's in scope, so decide which one you mean.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    yes like i said that would work, but, what exacltydo you mean by,i have two cubes in scocpe? the other cube is decalred outside the class by using an enum, and the other one is declared inside the class?

    and how come for the other 2 enums, i could'nt use the scope resolution on them? ie, WHATSHAPE::SQUARE // error, or WHATSHAPE::TRIANGLE // error troo,

    many thanks,

Popular pages Recent additions subscribe to a feed