0

Having something like this (example):

enum {
  label1,
  label2,
  //label3,
  label4,
  total}

Is it possible to check if any of the labels are present?

I need the total value in order to create matrices of the correct size, but need to know which of the labels are present in the list in order to perform operations specific to each item.

2
  • 1
    Not really possible in a sense you cant do Enum::label3 == undefined. Use list of strings or a smarted Enum class Commented Jun 4, 2013 at 19:54
  • It sounds like an enum might not be the best thing to use in your situation. Commented Jun 4, 2013 at 19:58

1 Answer 1

1

Try this:

enum My_Labels
{
    label1,  
    label2,  
    // label3,
    label4,  
    total
};

static My_Labels check1 = label1;
static My_Labels check2 = label2;
static My_Labels check3 = label3;
static My_Labels check4 = label4;

You should get a compilation error for any missing elements.

Also, if you comment out label3, the value of label4 changes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.