Clause 20: Try to use reference-to-constent instead when passing objects, Pass-by-value

Source: Internet
Author: User

Note that in the case of C + +, the underlying compiler, the reference type is often implemented by pointers, so pass-by-reference is often passed a pointer, which is often a bit more expensive to pass a reference for C + + built-in types. But this cannot be a reason for not using pass-by-reference for all small objects.

Summary:

1. Try to replace Pass-by-value with Pass-by-reference-to-const, which is not only more efficient, but also avoids cutting problems

2. These rules do not apply to built-in types, STL iterators, and Function objects , which are more appropriate for these kinds of pass-by-value.

Clause 20: Try to use reference-to-constent instead when passing objects, Pass-by-value

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.