Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualThe King2

Posted 03 April 2013 - 09:23 AM

Hello,

 

I've recently converted all my enums to strongly typed enums, like this:

 

enum class WindowBorders : unsigned char {
    None            = 0x00,
    Left            = 0x01,
    Right            = 0x02,
    Bottom            = 0x04,
    LeftBottom        = 0x05,
    RightBottom        = 0x06,
};

 

Now these work as flags, and previously I could have been checking if a variable contained one of those flags by coding:

 

unsigned char m_cBorder = LeftBottom;
if( (m_cBorder & Left) == Left )
//left border was clicked

Now this won't work anymore, I have to treat LeftBottom and RightBottom as seperate cases, while they essentially are just an addition of bottom and eigther left or right border, and also work that way. That causes a lot of unecessary code for my window object. The (german) compiler gives me somemessage about "&" only working for enums without a range restriction (?). Is this really impossible to achieve or is there some way to still do this?


#2The King2

Posted 03 April 2013 - 09:23 AM

Hello,

 

I've recently converted all my enums to strongly typed enums, like this:

 

enum class WindowBorders : unsigned char {
    None            = 0x00,
    Left            = 0x01,
    Right            = 0x02,
    Bottom            = 0x04,
    LeftBottom        = 0x05,
    RightBottom        = 0x06,
};

 

Now these work as flags, and previously I could have been checking if a variable contained one of those flags by coding:

 

unsigned char m_cBorder = LeftBottom;
if( (m_cBorder & Left) == Left )
//left border was clicked

Now this won't work anymore, I have to treat LeftBottom and RightBottom as seperate cases, while they essentially are just an addition of bottom and eigther left or right border, and also work that way. That causes a lot of unecessary code for my window object. The compiler gives me some (german) message about "&" only working for enums without a range restriction (?). Is this really impossible to achieve or is there some way to still do this?


#1The King2

Posted 03 April 2013 - 09:22 AM

Hello,

 

I've recently converted all my enums to strongly typed enums, like this:

 

enum class WindowBorders : unsigned char {
    None            = 0x00,
    Left            = 0x01,
    Right            = 0x02,
    Bottom            = 0x04,
    LeftBottom        = 0x05,
    RightBottom        = 0x06,
};

 

Now these work as flags, and previously I could have been checking if a variable contained one of those flags by coding:

 

unsigned char m_cBorder = LeftBottom;
if( (m_cBorder & Left) == Left )
//left border was clicked

Now this won't work anymore, I have to treat LeftBottom and RightBottom as seperate cases, which causes a lot of unecessary code for my window and other object. The compiler gives me some (german) message about "&" only working for enums without a range restriction (?). Is this really impossible to achieve or is there some way to still do this?


PARTNERS