More effective C + + clause 70 million do not overload &&,| | And, operator

Source: Internet
Author: User

1. Built-in && and | | The operator has a "short-circuit evaluation" feature. For && if the first operand is true, then && returns to true, no longer evaluates the second operand, | | Instead, use this feature to write the following code:

Char *p; .. if (p>0&&strlen (P) >) ...
View Code

Once overloaded,&& and | | The left and right operand is two no points before and after the parameters, that is, the characteristics of short-circuit evaluation is not when the function is called, all parameters are evaluated and passed in and C + + does not specify a parameter of the job order, the previous code can not be used.

2. For the built-in comma operator, evaluate each operand from left to right, and finally return the rightmost operand (can be multiple commas) with

Once overloaded, the attributes that are evaluated from left to right are also gone (even if the overloads are the same as the member functions).

3. Operators that cannot be overloaded:

. .*                       ::                        ?:

New Delete sizeof typeID

static_cast dynamic_cast const_cast reinterpret_cast

More effective C + + clause 70 million do not overload &&,| | And, operator

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.