0

How would I get an enum to be called in classes, such as this one:

enum race {White, Black, Asian};

so I can call it in a constructor such as this one:

Emp (string first_name, string middle_name, string last_name,
     int soc_security, string ID, //enum race//); //errors come up for enum race
2
  • 1
    Any particular programming language... ? I want to guess C++ but //...// isn't a valid block comment in C++. Commented Feb 27, 2017 at 22:59
  • If you are planning on doing more than this tiny bit in c++ you should learn it with a technique other then guessing. Perhaps a good book Commented Mar 1, 2017 at 1:08

1 Answer 1

1

You haven't specified a language, so I'm just going to guess C++. You're almost right, except you forgot to specify the parameter name in your argument list:

enum race { White, Black, Asian }

...

// example declaration, parameter named 'r', for example:
void example (..., enum race r);

// example definition:
void example (..., enum race r) {
    // do things with 'r'.
}

You don't have to specify the parameter name in a declaration but you absolutely have to in a definition if you expect to use that parameter in the function body. Note, by the way, that it's not actually required to specify enum in the parameter list, so this also works:

void example (..., race r);

In the future please use one of the available language tags, such as , , , etc. on your posts. Not only will it activate the appropriate default syntax highlighting for code snippets, but it will greatly increase the visibility of your question and help you get good answers quickly.

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

3 Comments

I am using C++, but when I put in the parameters like this: Emp (string first_name, string middle_name, string last_name, int soc_security, string ID, int year, int month, int day, enum race{White, Black, Asian}); errors pop up for enum race.
@JordynHamilton Why would you put the parameters in like that?
@JasonC Because the OP is just guessing how c++ works.

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.