help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enumeration Issue


From: Bradley Millman
Subject: Re: Enumeration Issue
Date: Mon, 30 Oct 2006 17:20:01 -0500
User-agent: Thunderbird 1.5.0.7 (X11/20060911)

You are basically correct....use enum xpto {one=0, two, three, NUMELEMENTS}; to get the number of elements in the enum. There is no way to change this during run time. All enum is doing is creating some handy symbols for you to use. (In c++ the enum is a 'type safe' way of insuring you are only using enum values and not just any integer). Forget about adding to an enum at run time. I don't think much of doing things that are compiler specific and why bother when you have a generic way to do it.

Brad

Paulo Matos wrote:
Hello all,


Guess I have an enumeration:
enum xpto {one, two, three};

How can I compute the number of elements in this enumeration?
I could in this specific case do:
enum xpto {one, two, three, NUMELEMENTS};

and each time I add an element I add it _before_ NUMELEMENTS, still
being this a constant during runtime (don't think there's a way to ad
an element during runtime) there could be a compiler specific way to do
this, right? Is there any?

Regards,

Paulo Matos



reply via email to

[Prev in Thread] Current Thread [Next in Thread]