Thread overview
enum help
Aug 27, 2008
Michael P.
Aug 27, 2008
Denis Koroskin
Aug 27, 2008
Derek Parnell
Aug 28, 2008
Michael P.
Aug 27, 2008
Zarathustra
August 27, 2008
So, I'm having problems with enums.

Let's say I have this piece of code:

enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
void main()
{
Card MyCard;
MyCard = NINE;
}

I get an error saying that NINE is undefined and it cannot be implicitly converted to type int. How would I make a Card variable get the value of NINE?
August 27, 2008
On Wed, 27 Aug 2008 23:21:14 +0400, Michael P. <baseball.mjp@gmail.com> wrote:

> So, I'm having problems with enums.
>
> Let's say I have this piece of code:
>
> enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
> void main()
> {
> Card MyCard;
> MyCard = NINE;
> }
>
> I get an error saying that NINE is undefined and it cannot be implicitly converted to type int. How would I make a Card variable get the value of NINE?


Try this:
> MyCard = Card.NINE;
August 27, 2008
On Wed, 27 Aug 2008 15:21:14 -0400, Michael P. wrote:

> enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
> void main()
> {
> Card MyCard;
> MyCard = NINE;
> }
> 
> I get an error saying that NINE is undefined ...

This is because the enum declaration creates its own namespace. This is so you can disambiguate between different 'NINE' definitions...


 enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
 enum Pin  { ONE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE }
 void main()
 {
 Card MyCard;
 Pin MyPins;
 MyCard = Card.NINE;
 MyPins = Pin.NINE;
 }


-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
August 27, 2008
Michael P. Wrote:

> So, I'm having problems with enums.
> 
> Let's say I have this piece of code:
> 
> enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
> void main()
> {
> Card MyCard;
> MyCard = NINE;
> }
> 
> I get an error saying that NINE is undefined and it cannot be implicitly converted to type int. How would I make a Card variable get the value of NINE?

Use anymous enumerate,
_______________________________________________
enum{
  NINE  =  0,
  JACK  =  2,
  QUEEN =  3,
  KING  =  4,
  TEN   = 10,
  ACE   = 11
}

void main{
	auto MyCard = NINE;
}
_______________________________________________

aliases
_______________________________________________
enum Card{
  NINE  =  0,
  JACK  =  2,
  QUEEN =  3,
  KING  =  4,
  TEN   = 10,
  ACE   = 11
}

alias Card.NINE  NINE ;
alias Card.JACK  JACK ;
alias Card.QUEEN QUEEN;
alias Card.KING  KING ;
alias Card.TEN   TEN  ;
alias Card.ACE   ACE  ;

void main{
  Card MyCard = NINE;
}
_______________________________________________

or namespace Card
_______________________________________________
enum Card{
  NINE  =  0,
  JACK  =  2,
  QUEEN =  3,
  KING  =  4,
  TEN   = 10,
  ACE   = 11
}
void main{
  Card MyCard = Card.NINE;
}
August 28, 2008
Derek Parnell Wrote:

> On Wed, 27 Aug 2008 15:21:14 -0400, Michael P. wrote:
> 
> > enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
> > void main()
> > {
> > Card MyCard;
> > MyCard = NINE;
> > }
> > 
> > I get an error saying that NINE is undefined ...
> 
> This is because the enum declaration creates its own namespace. This is so you can disambiguate between different 'NINE' definitions...
> 
> 
>  enum Card { NINE = 0, JACK = 2, QUEEN = 3, KING= 4, TEN = 10, ACE = 11 }
>  enum Pin  { ONE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE }
>  void main()
>  {
>  Card MyCard;
>  Pin MyPins;
>  MyCard = Card.NINE;
>  MyPins = Pin.NINE;
>  }
> 
> 
> -- 
> Derek Parnell
> Melbourne, Australia
> skype: derek.j.parnell

Thanks, that worked.
-Michael P.