Why can you not change the operator precedence when you overload operators in C++? For example, if you had a class in which it would make sense to do addition before multiplication, how could you make the addition operator have higher precedence than the multiplication one?
This is different from this question Operator overloading and precedence because I am asking why, and how to work around this restriction.
I would prefer to avoid compiler customization, and use only C++14 standards. Third-party libraries are OK.
Traditional compiler design parses the grammar first, before figuring out where each operator comes from.
Compiler design tools like YACC existed long before C++. As such, traditional compilers evolved over time following the general principle of parsing the syntax of the source code first, then trying to figure out what to do with each operator. So, the compiler sees the structure of the language first, and foremost; and the C++ standard actually wants to make it possible to write a C++ compiler without reinventing every wheel that has been invented, already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With