Reputation: 1
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
Upvotes: 0
Views: 367
Reputation: 40406
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 c, c++, java, 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.
Upvotes: 1