thanks for entering this post, I've been coding in c++ recently and came across an issue while trying to initialize 5 member variables of a class Input in a single line. This member variables were defined in the header file and in the source file I set their values to false within the constructor. when i try to initialize them separately, each one to false, the application works as expected, however when I try to intiialize all of the 5 boolean variables to false, it's working as if I haven't set any of them to false. I tried to output the value of a variable m_isWindowCloseButtonClicked and it outputs 205, no idea why, however, when I inidivudallly initialize each one of these booleans it output that variable value as 0, as expected
Asked
Active
Viewed 149 times
-5
-
3Please do not paste images - copy the code itself. – lorro Aug 16 '22 at 16:04
-
1`m_isKeyPressed, m_isWindowCloseButtonClicked, m_isRightMouseButtonClicked, m_isLeftMouseButtonClicked, m_isMiddleMouseButtonClicked = false;` does not set all five of those variables to `false`. Where did you get the idea that it would? – Nathan Pierson Aug 16 '22 at 16:07
1 Answers
1
Do not paste images instead of code, copy the code.
Also, when initializing multiple variables, don't use ,
to specify the variables. This won't work as expected:
a, b, c = false;
Use instead:
a = b = c = false;

lorro
- 10,687
- 23
- 36