C ++ learning 4. overloading the C ++ Operator

Source: Internet
Author: User

 

----- This article is based on the knowledge of overloading the C ++ operator.

 

 

 

Why reload operators?

1. Make the class behave like the built-in data type

2. More control over Program Performance

 

 

 

 

 

Restrictions on Operator Overloading

1. New operators cannot be added.

2. Some operators cannot be overloaded.

3. The number of operators cannot be changed.

4. The operator priority cannot be changed.

5. built-in operators cannot be redefined.

 

 

Selection in operator overload

A. method or global function

 

 

There are three different types of Operators

1. It must be a method operator.

These operations are meaningless.

2. It must be a global function operator.

When the operand on the left of the operator needs to be another type of variable.

3. Operators available for both.

 

 

B. Select the parameter type

 

 

C. Select the return type

You should properly compile the overload operator so that it has the same performance as the operator corresponding to the built-in data type and returns the same type.

D. Select Behavior

 

 

Operators that should not be overloaded

The bitwise operator, double boolean operator, and comma operator ,.

The above knowledge is as follows:

 


From my dream pursued by me

Related Article

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.