PDA

Click to See Complete Forum and Search --> : Problem comparing two Enum


Khavoerm
Dec 18th, 2001, 01:06 PM
Hello,
For my program, I created an enum called Month. One the my function requiert a Month arguments and check if it is the current month. Here my function:

void CAgenda::SetMonth(enum Month NewMonth)
{
Month curMonth = GetCurrentMonth();

if(NewMonth != curMonth)
{
...Some codes
}
else
{
...Some codes
}
}

I get this error on line if(NewMonth != curMonth) :
error C2677: binary '!=' : no global operator defined which takes type 'enum Month' (or there is no acceptable conversion)

How could I compare the two Month?

HarryW
Dec 18th, 2001, 04:59 PM
Drop the 'enum' before 'Month'. You don't have to do this in C++, it's something that you used to have to do in old C compilers but isn't necessary any more. The same goes for 'struct'.

Try it like this:

void CAgenda::SetMonth(Month NewMonth)
{
Month curMonth = GetCurrentMonth();

if(NewMonth != curMonth)
{
...Some codes
}
else
{
...Some codes
}
}

Khavoerm
Dec 18th, 2001, 08:19 PM
Oh yeah that worked. I remembered I tried without enum, but it couldn't compile... Thank you for your help.