I know what it's for, but I never really use enum for anything, so here's my question:
I am working on banking software. I have a base class that has an account core type member. It's an int that represents any of the various types of products the bank can offer. If an object is being spawned from a derived class, can I use enum to constrain the core account type to only those values that correspond to relevant core types for the class being derived? For example, if I write a loan module, the core account type should only be a mortgage, business loan, credit card, etc. I want the compiler to throw an error (or possibly be caught in a try/catch block) if the core account type is set to something that doesn't apply to a loan (i.e. a savings or checking account).
Can enum do this? How would I make a function that accepts only one of the enumerated types (even though the member is just an int)?
Start Free Trial