Results 1 to 3 of 3

Thread: Problem comparing two Enum

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Québec, Canada
    Posts
    131

    Problem comparing two Enum

    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:

    PHP Code:
    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?
    Khavoerm Irithyl

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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:

    Code:
    void CAgenda::SetMonth(Month NewMonth)
    {
                    Month curMonth = GetCurrentMonth();
    
        if(NewMonth != curMonth)
        {
            ...Some codes
        }
        else
        {
            ...Some codes
        }
    }
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Québec, Canada
    Posts
    131
    Oh yeah that worked. I remembered I tried without enum, but it couldn't compile... Thank you for your help.
    Khavoerm Irithyl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width