Effective C + + Item 1: View C + + as a language federation

Source: Internet
Author: User

Effective C + + Chapter 1. Make yourself accustomed to C + + (Accustoming yourself to C + +) Item 1. View C + + as a language federation (View C + + as a federation of Languages)

Consider C + + as a federation of four sub-languages, where codes and practices tend to be simple, straightforward, and easy to remember in a given sub-language. But moving from one sub-language to another, the code may change.

    • C --c++ is based on C. Chunks (blocks), statements (statements), pre-processor (preprocessor), built-in data types (built-in), arrays (types), pointers (arrays), all from C.
    • object-oriented C + + -This is part of C with Classes: Classes (including constructors and destructors), Encapsulation (encapsulation), Inheritance (inheritance), Polymorphic (polymorphism), virtual functions (dynamic binding) ... Wait a minute.
    • Template C + + -This is the generic programming (generic programming) part of C + +.
    • STL --stl is a template library for containers (containers), iterators (iterators), Algorithms (algorithms), and function objects (functions objects) of the statute of the very good close coordination and coordination.

Different sub-languages have different codes and therefore use no strategy. Pass-by-value is usually more efficient than pass-by-reference for built-in (aka C-like) types, but for object-oriented C + +, because of the existence of user-defined constructors and destructors, Pass-by-reference-to-const tend to be better. This is also true when using Template C + + because you do not know the type of object you are working with. But once the STL is crossed, because iterators and function objects are all shaped on the C pointer, the old C pass-by-value code is once again applicable to STL iterators and function objects.

Please remember:

    • The code for efficient programming of C + + changes depending on what part of C + + you use.

Effective C + + Item 1: View C + + as a language federation

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.