1. In the beginning, C + + was just C plus some object-oriented features, originally named "C with Classes" (C with Class).
2. Today's C + + is already a multi-generic programming language, supporting process form (procedural), object-oriented (object-oriented), function (functional), generic (generic), meta-programming ( metaprogramming) language. These abilities and elasticity may provoke some confusion: all "appropriate usages" seem to have exceptions, how do you understand such a language?
3. The simplest approach is to treat C + + as a federation of related languages. In one of its sub-languages, the codes are simple to understand and easy to remember. But when moving from one sub-language to another, the code may change. C + + has a total of four sub-languages:
C:c++ is based on C. Chunk (Blocks), statement (statements), preprocessor (proprocessor), built-in data type (built-in), array (types), pointer (arrays) All of this comes from C, and many C + + solutions to problems are but higher-level C solutions.
obiect-oriented C + +: This is part of the "C with Classes" appeal: Classes (including constructors and destructors), Encapsulation (encapsulation), Inheritance (inheritance), polymorphism ( polymorphism), virtual function (dynamic binding) ... And so on, this part is the direct implementation of object-oriented on C + +.
Template C + +: This is the generic programming (generic programming) part of C + +, as templates powerful, they bring a new paradigm (programming paradigm), the so-called template Meta-programmingtmp, template meta-programming).
STL (Standard Template Library): It includes containers (containers), iterators (iterators), Algorithms (algorithms), and Function objects (functions objects).
4. When switching from one sub-language to another, the Code of efficient programming may have to change the strategy, for example, for built-in types (c-like), Pass-by-value is more efficient than pass-by-reference (Pass-by-value takes up more memory, While the Pass-by-value passes through the first layer of the pointer, it takes more time to package, but when moving from C part of C + + to obiect-oriented C + +, because of the existence of user-defined constructors and destructors, Pass-by-reference is obviously more efficient than pass-by-value, especially when using template, because the type of object being processed is not even deterministic, but once you cross the STL, for iterators and function objects, the old C The Pass-by-value code applies again (since iterators and function objects are all shaped on the C pointer).
5. In summary, C + + is composed of four sub-languages, each with its own statute, and the use of different sub-languages, C + + 's Efficient programming code is also changed.
Effective C + + clause 1 View C + + as a language federation