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