I learned enums when I learned C and from time to time I keep myself reminding about it and most of the time by re-reading from some source,it occurred to me that this is d
One use of enums is to make code clearer at the call site. Compare:
//Usage: Kick(Dog);
enum PetType
{
Cat,
Dog
};
void Kick(PetType p)
{
switch(p)
{
case Cat:
//Kick Cat
break;
case Dog:
//Kick Dog
break;
default:
//Throw an exception.
break;
}
}
//Usage: Kick(false);
void Kick(bool isCat)
{
if (isCat)
{
//Kick Cat
}
else
{
//Kick Dog
}
}
Even though a boolean would work just as well, someone unfamiliar with the function will need to work much harder to determine what it does in the case that a boolean was used. Kick(Dog) is much clearer than Kick(false).