Negative tive C ++ clause 19: differentiate member functions, non-member functions, and friend Functions

Source: Internet
Author: User

These terms draw the following conclusions:

Suppose f is a function to be correctly declared, and C is a class related to it:

1. The virtual function must be a member function. If F must be a virtual function, make it a member function of C.

2. Operator> and operator <must not be member functions. If F is Operator> or operator <, make f a non-member function. If F also needs to access non-public members of C, make f a friend function of C.

3. Only non-member functions perform type conversion on the leftmost parameters. If f needs to convert the type of the leftmost parameter to make f a non-member function. If F also needs to access non-public members of C, make f a friend function of C.

4. In other cases, it is declared as a member function. If none of the above is true, make f a member function of C.

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.