I am determined to read D & E twice or three times, so I will take a reading note and write down what I think is necessary.
1. inline
In C with a class, the member functions implemented in the class declaration can be inline.
Class Stack {// will be inline char POP () {If (top <= min) error ("Stack underflow"); return * -- top ;}};
The Inline keyword provided in C ++ can also be used for inline.
In addition, non-member functions modified by static have the internal connection attribute, which may also be dropped in line.
2. Narrow Conversion
Early ideas do not allow implicit conversion of "Broken Information". However, it was discovered thatProgramThere are a large number of int to Char conversions .....
Implicit narrowing conversion is usually given to warning, unless explicitly called for conversion. Except for int to Char...
3. Protection Concept in C ++ (public/private/protected)
Protection is provided through the compile-time mechanism to prevent unexpected events, rather than spoofing or intentional infringement.
The access permission is granted by the class itself, rather than the unilateral access.
Access control is implemented by name instead of the type of the named thing.
The Protection Unit is class, not individual objects.
The control is access, not visibility.
4. Overwrite and virtual function matching
Class base {public: Virtual void F (); Virtual void g (INT) ;}; class dervided: public base {public: void F (); // overrides base :: F () void g (char); // doesn't override base: G ()};
The non-virtual function dervided: G has no relationship with base: G, but overwrites it. This can easily lead to errors and the compiler does not give any warning.
5. Masking of base class members
The name in the derived class masks any object goods functions with the same name in the base class.
6. + = Operator
+ = These operators are more basic, and they are more efficient than conventional Arithmetic Operators. it is best to first define the + =, * = type of assignment operator functions as member functions, and then the + and * types as global functions.
7. Origins of const
The father of C ++ said that readonly was required, so the standard was finally added to const. however, the const here is a little different from readonly, that is, the language does not have any mechanism to ensure that this is readonly.
Also, the global const variable has the internal link attribute. this is related to optimization. The standard assumes that you do not modify this const variable, so you do not need to connect to the same object in other units.
8. Life Cycle of temporary variables
A temporary variable must be a subexpression of an expression. When a temporary variable is no longer a subexpression of any expression, it can be parsed.
The term is the end of a complete expression.
9. Restrict pointer
The restrict pointer is used for optimization and mainly for numerical computation. If there is no special requirement, you do not need this keyword. Otherwise, the content of the two pointers has overlapping parts, which may cause optimization errors.
10. fine-grained Overloading
Reload will first match the exact type. If the matching is not successful, the type will be upgraded or implicitly converted.
In addition, 'X' is Char in C ++ and INT in C.
11. Reload matching rules
1) matching is not converted, or it is only inevitable to convert, for example, array name to pointer, function name to function pointer, and t to const T.
2) matching with Integer type elevation, defined in ansi c, Char to int, short to int, their corresponding unsigned type, and float to double.
3) use standard conversion to match. For example, int to double, dervied * to base *, unsigned int to int, etc.
4) use User-Defined conversion matching, including constructor and conversion operator.
5) used the ellipsis (...) matching in the function declaration.
If there are two highest matches, there is ambiguity, a compilation error will be generated.
12. noncopyable
Simply define both the copy constructor and the value assignment function as private.
13. Prevent Derivation
The Destructor is private...
In fact, C ++ 11 has the final keyword, which can also be used to place the Derivation
14. Copy by Members
Object replication is defined as copying by Members for all amorphous members and base members.
If the pointer member copies the constructor and the value assignment function according to the default copy, it should provide the warning.
15. Front ++ and back ++ Operators
Class ptr_to_x {X & operator ++ (); // front x operator (INT); // rear };
16. bool type
Bool is a special Integer type with the literal values true and false. non-zero values can be implicitly converted to true, and true can be implicitly converted to 1; zero values can be implicitly converted to false, and false can be implicitly converted to 0.
15. Relax the coverage rules
The return type of the function, which can be overwritten without strict matching.
Class B {public: Virtual B * clone () {return New B (* This) ;}}; Class D: Public B {public: Virtual D * clone () {return new D (* This) ;}// void H () ;}; void Gg (B * pb, D * PD) {B * PB1 = Pb-> clone (); D * pd1 = Pd-> clone (); Pd-> clone ()-> H (); D * Pd2 = Pb-> clone (); // error Pb-> clone ()-> H (); // error}
16. Protected keyword
Mark is the main designer of interviews. He persuaded his father to add protected in C ++. There are 10 thousand reasons to support this idea .....
Five years later, Mark banned the use of protected members in interviews, because they have become the root cause of many program errors...
17. Correct Use of rtti
1) the most desirable is that the runtime type information mechanism is not used at all, and it relies entirely on static type checks.
2) if not, use dynamic conversion.
3) If necessary, use typeid () for comparison.
4) if you really need to know more information about a type, you need to use typeid-related operations.