If I want to implement the following code, would enums be appropriate? I’ve looked up a few questions on enums, but I’m still a bit unsure.
if (dayOfWeek == Monday)
{
// Do something
}
else if (dayOfWeek == Tuesday || dayOfWeek == Wednesday)
{
// Do something else
}
If this seems right, how would I go about initialising the enum? Would it go in the header or implementation file?
Without getting too detailed about alternatives — Yes.
I typically declare an enum in C like so:
MONwould be your library or organization’s prefix.DayOfWeekwould be the enum name within the library, then the values are appended.Although it’s wordy, you tend to avoid collisions quite well.
In the header, if you want it to be used by multiple files, else in the implementation file.