How to enum an enum?

From: Ernst Murnleitner (mur-spam_at_awite.de)
Date: 11/13/03


Date: Thu, 13 Nov 2003 00:42:37 +0100

Hello readers,

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
        if(p->IsA(e))
                  iNum ++;
cout << "Item is Member of " << iNum << " families" << endl;
}

It seems not to be possible? Is there another elegant solution

Greetings
Ernst



Relevant Pages

  • Re: Iterating through an enum???
    ... to have to name and specify them. ... enum), although I can see the advantage of defining consts in a namespace ... > and/or too many that it isn't practical to enumerate all, ... compiler is free to get rid of the allocation. ...
    (microsoft.public.vc.language)
  • Re: Behaviour of enumerated types
    ... >>> than using their index values as keys to other ordered info? ... If you want sequence numbers, use enumerate(). ... the enum object itself can be used directly as an iterable. ...
    (comp.lang.python)
  • Re: How to enum an enum?
    ... "Ernst Murnleitner" wrote... ... > I want to enumerate all values in an enum, ...
    (comp.lang.cpp)
  • Can anyone help me?
    ... After i install the Toaster bus driver in windows98 successfully, ... find way to enumerate the virtual device using enum.exe. ... "enum -p 1" in console line,it couldn't work properly and broke out ...
    (microsoft.public.development.device.drivers)