0x00 c ++ principles: overloading the existing operators can not change the binding and priority:
When Token operator identifier as a lexical analyzer, can not dynamically add, Token operator does not recognize other Lexer not defined at compile time, and overloading the existing operators only to add semantic parsing Token operation, specified call sign point to it, so the binding operator action is dynamic, however, to distinguish between token units in the lexical analyzer to write dead, fixed.
Meanwhile, combine and priorities are fixed on parsing level-coded, static and unchangeable.
(Guess, not confirmed)
0x01 c ++ logically how to parse operation expression
The main operator is used to express the distinction keyword
Unary operator
Expression | Code calls | Write a function overloading |
a++ | a.operator ++(0) | DataType operator ++(int) |
++a | a.operator ++() | DataType operator ++() |
Binary operator
Expression | Code calls | Write a function overloading |
a << b | a.opearator<<(b) | DataType operator << (const DataType & b) |
Ternary operator
Not known
0x02 c ++ support complex data operations with two types of
Write member function in the class of operator overloading
0x03 C ++ functions to support complex data calculating two different types of
Write non-member function outside the class operator overloading
And the class distinction, as an example to a + b, because the outer class, so there is no class can call this domain, it is overloaded transmission parameters required operand and operand transfer
Therefore, with a + b can DataType operator + (const DataTypeA & a, const DataTypeB & b)
0x04 on comprehensive, c ++ operator overloading, the compiler understand the principle of hierarchy will be very simple, the main figure opearator key dynamic binding of operator symbols can be