//1. When we overload an operator, it includes the type of the operand and the type of the return value is defined by the operator, but the number and precedence of the operand, the binding law is immutable.//2. When an object is used as an rvalue, the value (content) of the object is used. When an object is used as an lvalue, the object's identity (in-memory position) is used. //3. Compound expression: Refers to an expression that contains two or more operators. Finding the value of a compound expression requires that the operator and the operand are logically grouped together first. The combination of the arithmetic objects is determined by the precedence and the binding law. //parentheses disregard the common rules of composition, and the parts enclosed in parentheses are evaluated as a unit and then combined with other parts by priority. //The precedence specifies how the operands are combined, but does not indicate that the operator object is evaluated in the order described. For operators that do not specify the order of execution, if the expression points to and modifies the same object, an error is raised and undefined behavior is generated. //in an expression of a shape such as f () + g () * H () + j (), the precedence specifies that the return values of G () and H () be multiplied. Combined with the law, the return value of f () is added to the result of the multiplication and then to the return value of J (), but the order of invocation for the four functions is undefined. //If you change the value of an operand, do not continue to use the operand elsewhere in the expression, otherwise it will result in undefined behavior. There is one exception to this rule: the above rules are invalid when you change the operands of an operand to be an operand of another subexpression itself. //For example, in the expression *++iter, the increment operator changes the value of ITER, and the value of ITER (which has been changed) is the operand of the dereference operator, where the order of evaluation is not problematic. Because the increment operation must first evaluate and then turn to the dereference operator. intF0 () {return 0;}; intF1 () {return 0;}; intValue = F0 () + F1 ();//the call to F0 () and F1 () is definitely called before the +, but it is not known whether F0 () first Call or F1 () is called first. If F0 () and F1 () modify the same object, the value is defined. //There are 4 types of operators that specify the order of execution://&& The value of the left object first, and the value of the right object is only evaluated if the left object is true. //| | The value of the left object is evaluated first, and the value of the right object is only evaluated if the left object is false. //cmd? EXPL:EXP2 first the value of CMD, if True then continue to seek the value of EXP1, if it is false to seek EXP2 value. //, the value of the left expression is first evaluated, and then the value of the right expression is discarded, and the true evaluation result is the value of the right-hand expression. //4. Before the expression is evaluated, the operands of the small integer type (bool, char, unsigned char, short, unsigned) are promoted to a larger integer type (generally int). //5. Overflow problem: Data overflow is an undefined behavior whose results are unpredictable and behave differently on different machines. CharValue0 = -;//This machine overflow way: 500 namely 0X1F4, because Value0 is char type, this machine is small end mode, so first store low, high is discarded, so value0 in memory for 0xf4, namely 244, overflow again, so value0 value is-( 266-244) that is -12//6. The relational operator (< <= > >= = =) returns the type bool. form a < b < C; The result of a < b is compared to C, and if C is a value greater than 1, then the expression is constant true. //7.++ and--the predecessor version returns its object itself as an lvalue, but the subsequent version returns a copy of the original value of the object as the right value. //8. Conditional operator: Returns an lvalue when all two of its expressions are lvalue or can be converted to the same lvalue type. Otherwise, the right value is returned. The conditional operator has a low priority, which is one level higher than the assignment operator. //9.sizeof://returns an expression or the number of bytes of a type name//sizeof does not actually calculate the value of its operand//satisfies the right binding law//executing sizeof on a reference type gets the amount of space the referenced object occupies//performing sizeof on an array will get the entire size of the space//executing sizeof on a vector or string only returns the size of the fixed part of the type and does not calculate the space occupied by the elements in the object//return value is a constant expression//10. Comma operator: First, the value on the left, and then discard the evaluation result, return the value of the right expression, if the right-hand expression is an lvalue, its return is also an lvalue, otherwise the right value//11. Where an implicit type conversion occurs://in most expressions, a shape smaller than the int type is first converted to a larger integer type//in a condition, a non-Boolean type is converted to a Boolean type//The right-hand expression is converted to the type of the left operand during initialization and assignment//If an operand of an arithmetic type or a relational operation has more than one type, it needs to be converted to the same type (the operator's operand will be converted to the widest type). C + + does not perform arithmetic operations on different types of objects, but rather first evaluates the type of the operand according to the type conversion rule. //when a function is called//in most expressions that use arrays, the array is converted to a pointer to the first element of the array. Function will also perform a similar conversion// intValue1 =1.2+2;//value1 = 3 evaluates the procedure to add 2 to a double and 1.2, and then assigns the result 3.2 to the int type//12. Operator Precedence and Union law: /* First level::: Global scope left Associative:: Class scope left Associative:: namespace scope left associative second level: . Member selection left associative--member selection left associative [] subscript left associative () function call left associative () Type constructs left associative third level: + + post increment operator Right Union--post decrement operator right associative typeid type right knot typeID run-time type right combines explicit cast type conversion right combined with static_cast const_cast, reinterpret_cast, Dynami C_cast Fourth Level: + + pre-increment operation right combination----------the right combination of the pre-descending operation ~ Anti-rightist combination! Logical non-right combination-unary minus right combination + unary plus right combination * dereference right associative &A mp Take address right combine () type convert right combine sizeof object size right combine sizeof value; sizeof type size right combined with sizeof (int); sizeof ... Parameter package size right combined with new Create object right associative new[] Create array right associative Delete Release object right associative delete[] free array right associative noexcept can throw exception right associative level fifth:->* point to Member selection The pointer to the left is combined with ptr->*p. * Pointer to member selection of the left binding ptr.*p sixth level: * Multiplication left combination /division left combination% take left combined Seventh level: + addition left combination -Subtraction left binding eighth level: << left shift left combination >> right shift Left binding Nineth level: < less than left combination > greater than left binding <= less than equals left combination >= is greater than or equal to left associative level tenth: = = equals left associative! = Unequal left-Associative 11th: & and left-associative level 12th: ^ Bitwise XOR or Left-associative level 13th: | Bitwise OR left-associative level 14th: && logic and left-associative level 15th: | | Logical or left-associative level 16th:? : Conditions Right combined with level 17th: = Right combination *=/=%= + = = << = >>= &= |= ^= xor equals level 18th: Throw throws an exception right in conjunction with level 19th: , comma-left combination*/
C++primer the fourth Chapter