I would like to overload the operator~
but not as an unary operator but as an binary operator so i can do thinks like a~b
. is there a way doing this in c++?
Asked
Active
Viewed 184 times
2

Exagon
- 4,798
- 6
- 25
- 53
-
4http://stackoverflow.com/a/4421708/560648 – Lightness Races in Orbit Apr 08 '16 at 15:53
-
If you want to invert each bit depending on the corresponding bit in a mask, then you can use the `^` operator; it's a bitlevel xor operation. – Cheers and hth. - Alf Apr 08 '16 at 16:05
2 Answers
12
There is no way of doing this in C++. Period.

Ed Heal
- 59,252
- 17
- 87
- 127
-
Agreed! And it would make parsing the code challenging (at least) for the compiler. – Frank Puffer Apr 08 '16 at 15:57
2
You could change the behavior by operator overloading, but you couldn't change the number of operands.
It is not possible to change the precedence, grouping, or number of operands of operators.

songyuanyao
- 169,198
- 16
- 310
- 405