C++ function takes ints, but example shows text? -
C++ function takes ints, but example shows text? -
this c++ question on confusing me. (i refreshing c++ after long time). reading illustration here. there 2 parts confuse me:
the first part:
in code line:
void namedwindow(const string& winname, int flags=window_autosize )
window_autosize input, far can tell, not int. when code line , run, works fine. input function literally 'window_autosize'. confused why works. how window_autosize int?
my sec question regarding lastly line, whereby say:
by default, flags == cv_window_autosize | cv_window_keepratio | cv_gui_expanded
i confused how/what means exactly... know | bitwise or, not clear means exactly...
thank you.
my input function literally 'window_autosize'
yep, window_autosize
in fact integer; simply @ fact it's default argument int
function parameter. wouldn't compile if wasn't int
// might have been defined #define window_autosize 23434 // number illustration // or const int window_autosize = 34234;
as sec question bitwise or
ing means bits in corresponding integral values or
ed together, lets example
cv_window_autosize = 0x0010 cv_window_keepratio = 0x0100 cv_gui_expanded = 0x1100
then corresponding operation give integral value every bit equal result of or
each position
cv_window_autosize | cv_window_keepratio | cv_gui_expanded = 0x0010 0x0100 0x1100 ------ 0x1110
on utilize of bitflags consider next : you have keyboard 4 keys :
ctrl, alt, del, shift
how many constants need define states keyboard can on ? lets enumerate states
all 4 keys pressed : 1 constant
3 keys pressed : takes (4 3) constants = 4 constants :
(4 3) = 4! / ( (4-3)! * 3! ) = 4
2 keys pressed : (4 2) = 6 constants
1 key pressed : 4 constants (the names of keys)
no key pressed : 1 constant
so sum you'd define :
1 + 4 + 6 + 4 + 1 = 16 constants
now if told need 4 different constants, each 1 having 1 bit on ? :
#define ctrlk 0x0001 #define altk 0x0010 #define delk 0x0100 #define shiftk 0x1000
then state keyboard can expressed combination of above : want express state shift key , del key pressed.
ctrlk | delk
the more combinations have, more technique pays off.
ofcourse (maybe see reference on bitflags) user code can probe integral value see bits switched on.
c++ function int bit-manipulation
Comments
Post a Comment