I have the following check in my C++ code:
if (not obj.someBoolean) {
// some code
} else {
// some other code
}
A print statement or gdb confirms that obj.someBoolean
(a bool
variable) is false
.
Yet the control goes to the else
block while using not
operator.
Interestingly, the !
variety of the operator works correctly when used in the above scenario (goes into the if
block).
Is this an issue with the way I am using not
?
Update (some more details on the scenario):
Throughout the code I have used not
in many places. But this is one scenario where this issue comes up (consistently).
Even the following code works (goes to if
block):
bool temp = not obj.someBoolean;
if (temp) {
// some code
} else {
// some other code
}
This is more like a single random point where it is happening.
I was curious as to why this behavior is caused.