5.2 Precedence of C + + overloaded operators

Source: Internet
Author: User

Reference: http://www.weixueyuan.net/view/6380.html

Summarize:

Overloaded operators cannot change the precedence and syntax characteristics of an operator.

Overloaded operators cannot change the precedence and syntax characteristics of an operator. For example, the addition operator overload function in the plural class of the previous section, the precedence of the addition is still unchanged after overloading, and is still a two-dollar operator after overloading.

Example 1:

int Main () {    complex c1,c2,c3,c4;         // ......    C4 = c1 + C2 * c3;     return 0 ;}

Continue to follow the complex plural class in example 1 in the previous section, define four objects of the class in Example 1, and then arithmetic, C4 = c1 + C2 * C3; This statement is also equivalent to C4 = c1 + (C2 * C3), although the addition and subtraction multiplier four operators are overloaded in the plural class, they do not change the attributes of their two-tuple operators, and they do not change their precedence, so their precedence is lower than the multiplication operator for overloaded addition operators.

The usage of the overloaded operator is not changed, for example, the addition operator always appears between two operands, and after overloading, the addition operator must still be placed between the two operands. For example, the addition and multiplication operators in Example 1 still maintain their original usage after overloading.

5.2 Precedence of C + + overloaded operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.