:D Hi folks. is there an XOR binary (bool,bool) operator in C++ please?
Printable View
:D Hi folks. is there an XOR binary (bool,bool) operator in C++ please?
Presumably you mean logical XOR as opposed to bitwise XOR (the ^ operator).
No. Use:
Code:(a || b) && !(a && b)
A better way to do this is :
( a != b ).
This will obviously only be true if one of a and b is TRUE and the other is FALSE.
If you wanted to, you could even define XOR to be !=, as in the following:
#define XOR !=
int main(int argc, char* argv[])
{
bool a = ( false XOR false );
bool b = ( false XOR true );
bool c = ( true XOR false );
bool d = ( true XOR true );
return 0;
}
This approach makes the intention of the code just as clear as an inbuilt xor operator would.
ok thanks