CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2008
    Posts
    48

    Is it possible that enum variables can take a value which is out of set ?

    Hi,
    Is it valid to assign a value which is out of the set to an ENUM variable ?

    for example
    -------------
    enum status
    {
    installed = 10;
    uninstalled = 20;
    repair = 30;
    };

    enum status current_status;
    current_status = 10;
    if(current_status == installed)
    current_status++;

    Can i write a code like this ?, here if the 'if' condition satisfies, the value of current_status will be set to 11 which is out of the set, is it going to be any error in this case.

    Thanks
    Kiran

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Is it possible that enum variables can take a value which is out of set ?

    An enum is just an int with a few compiler restrictions.

    The compiler may complain, but if you convince it to do as you say, you won't have any runtime problems resulting.

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

Featured