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

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to