This part is about More Effective C ++ Clauses 1 and 2. Take a note.
Bytes ----------------------------------------------------------------------------------------
1. pointer & reference
If there is a variable that needs to (represents) point to an object, but it is best
If a variable is used, it is best to make
Therefore
* pc = & rc = *pc;
This type of code cannot appear.
For pointer and reference, pointer can be null and can be re-assigned and pointed to another object. However, reference always points to its original object and cannot be re-assigned.
s1( s2( & rs = s1; * ps = &s1; rs = s2; ps = &s2;
2. C ++ transformation operators
In C ++, the transformation operators include four static_cast, const_cast, dynamic_cast, and reinterpret_cast.
Static_cast is mainly used for normal type conversion, but cannot be used to remove constants or variables.
Const_cast is mainly used to change the constants of the expression. It can be used to remove the const attribute of the variable. Other operations cannot be used.
Dynamic_cast is mainly used to implement the "safe downward or cross-system transformation actions" in the inheritance system ". That is to say, you can convert a pointer or reference to a base class to a pointer or reference to a subclass. If the conversion fails, a null pointer (when the pointer is converted) or an exception (when the conversion is referenced) is returned ).
Reinterpret_cast is mainly used to convert the type of function pointers.