How to make functions with flag parameters? (C++) -


How do I create a function with flags like how the Windows' CreateWindow (... style | style,. .), For example, a creative function:

  int CreateNum (flag flag) // ??? {Int num = 0; If (Flags == GREATER_THAN_TEN) number = 11; If (Flags == EVEN & amp; ((num% 2) == 1) num ++; else if (Flags == ODD & ((num% 2) == 0) num ++; return num; } / This is possible, and if so, how?   

"post-text" itemprop = "text">

You can define a NAM specifying the "single bits" values ​​(note that the enclosing straight only works as naming references here So that you can write MyFlags :: EVEN ):

  struct MyFlags {enum value {EVEN = 0x01, ODD = 0x02, ANOTHER_FLAG = 0x04, YET_ANOTHER_FLAG = 0x08, SOMETHING_ELSE = 0x10, SOMETHING_COMPLETELY_DIFFERENT = 0x20};}  

Use the following:

  int CreateNum (MyFlags :: Value flags) {if (Flags & MyFlags :: EVEN) {// something ...}} zero main () {CreateNum (MyFlags :: Value) (MyFlags :: EVEN | MyFlags :: Asymmetrical))}  

Or just like this:

  int CreateNum (Int flags) {if (flags and MyFlags :: EVEN) {// do something ..}} zero main () {CreateNum (MyFlags :: EVEN | MyFlags :: ODD); }  

You can only declare integer constants, but in my opinion Enum is clear.

Note: I updated the post, keep some comments in mind, thank you!


Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -