Issues with attention to C + + operator overloading

Source: Internet
Author: User
Tags arithmetic operators bitwise operators

C++primer Fourth Edition 435

1. Assignment (=), subscript ([]), Call (()), member Access Arrow (-) operator must be defined as member, when defined as non-member, compiler error

2. Like assignment, a conforming assignment operator should normally be defined as a member of a class, but no compilation error occurs when a compound assignment operator is defined as a non-member

3. Some other operators, such as self-increment, self-subtract, and dereference, that change the state of an object or a given type, should normally be defined as members of a class

4. Symmetric operations, such as arithmetic operators, equality operators, relational operators, and bitwise operators, are best defined as normal non-member functions


Operators that cannot be overloaded:

::       .*      . ? :


Issues with attention to C + + operator overloading

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.