Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:46:42+00:00 2026-06-02T07:46:42+00:00

Consider: enum Test { a = 3, b = 7, c = 1 };

  • 0

Consider:

enum Test
{
    a = 3,
    b = 7,
    c = 1
};

I want to access the enum using an index. Something like this:

for (i=0; i<n; i++)
    doSomething((Test)i);

How can I do something like this, where I will be able to access the enum using an index, though the members of the enum have different values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:46:43+00:00Added an answer on June 2, 2026 at 7:46 am

    This is the best you can do:

    enum Test { a = 3, b = 7, c = 1, LAST = -1 };
    static const enum Test Test_map[] = { a, b, c, LAST };
    
    for (int i = 0; Test_map[i] != LAST; i++)
        doSomething(Test_map[i]);
    

    You have to maintain the mapping yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why can't enum's constructor access static fields and methods? This is perfectly valid with
How can I use C++ enum types like C#? consider following definition in c++
I'm reviewing for a test, and I am stumped by this question. Consider the
Which is the appropriate (more readable) way of naming enumerator? will you consider: enum
Consider this: [Flags] enum Colors { Red=1, Green=2, Blue=4 } Colors myColor=Colors.Red|Colors.Blue; Currently, I'm
How can I access static method of the enum if given enum is a
Consider this example which prints out some device type stats. (DeviceType is an enum
Consider this code: public interface Foo extends Comparable<Foo> {} public enum FooImpl implements Foo
Consider this one template<typename T> struct A { enum class X { V =
So consider a function like this: public void setTemperature(double newTemperatureValue, TemperatureUnit unit) where TemperatureUnit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.