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
Jason C
  • 38,729
  • 14
  • 126
  • 182
  • 1
    Any particular programming language... ? I want to guess C++ but `//...//` isn't a valid block comment in C++. – Jason C Feb 27 '17 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](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Fantastic Mr Fox Mar 01 '17 at 01:08

1 Answers1

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.

Jason C
  • 38,729
  • 14
  • 126
  • 182
  • 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. – Jordyn Hamilton Feb 28 '17 at 22:52
  • @JordynHamilton Why would you put the parameters in like that? – Jason C Mar 01 '17 at 01:04
  • @JasonC Because the OP is just guessing how c++ works. – Fantastic Mr Fox Mar 01 '17 at 01:07