I recently came across this piece of code and I'm wondering why it works. Enum declaration:
enum BuildResult {
RESULT_ERROR,
RESULT_SUCCESS
};
Later, this Enum is used in an if statement (ignore the fact that it could instead be RESULT_ERROR
):
if (!objectHere->build_result == ClassNameHere::RESULT_SUCCESS)
I was not aware that you could use the not operator !
to flip the value of an Enum. Does this only work with Enums that have two states? Are there other kinds of implicit operators that can be used with Enums? I did find this question about manually declaring operators, but it doesn't seem to mention any implicit operators for enums.