Re: How to enum an enum?
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 11/13/03
- Previous message: Alexandre: "leak detected using valgrind"
- In reply to: Ernst Murnleitner: "How to enum an enum?"
- Next in thread: Shane Beasley: "Re: How to enum an enum?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 13 Nov 2003 02:19:17 GMT
"Ernst Murnleitner" <mur-spam@awite.de> wrote...
> I want to enumerate all values in an enum, e.g.:
> {
> enum Family{A=0, B,C, D = 100, E};
>
> BaseItem * p = Factory::Get...// BaseItem is the basis of many other items
> // BaseItem has a virtual Function IsA(f) which tests if the item is
member
> of Family f.
>
> int iNum = 0;
> for(Family e = A; e <= E, e++) // but this does not work, of course
for(Family e = A; e <= E; e++) // will work if you define
// operator++(int) for 'Family'
// and replace the , with a ;
> if(p->IsA(e))
> iNum ++;
> cout << "Item is Member of " << iNum << " families" << endl;
> }
>
>
> It seems not to be possible? Is there another elegant solution
Family operator++(Family f, int) {
if (f == C)
return D;
else if (f == E)
return A; // or not -- this is a wrapping increase
else
return Family(f + 1);
}
should do it...
Victor
- Previous message: Alexandre: "leak detected using valgrind"
- In reply to: Ernst Murnleitner: "How to enum an enum?"
- Next in thread: Shane Beasley: "Re: How to enum an enum?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|