Clause 26: Time to postpone variable definitions whenever possible
1. Throw an abnormal waste constructor halfway
2. Define variables within the loop, consume N constructors, n destructors, define variables outside the loop to consume N assignment functions, 1 constructs, one destructor;
Unless the assignment is consumed much less than construction and destruction, or if the code you are dealing with is highly sensitive, define the variable within the loop.
Clause 27: Try to do less transformational action
1, const_cast-----Out of the constant attribute, static_cast (implicit conversion display), dynamic_cast (from a base class pointer or reference of a hosted derived class to invoke the component of the derived class), reinterpret_cats low-level conversion
2, Static_cast<window> (*this). Onreise () function you might think that he called the function of the object base class, which actually calls the function of the copy of the object's base class. The access qualifier should be used instead.
3. To invoke the component of a derived class from a base class pointer or reference of a hosted derived class, you may be able to set a container to hold a bunch of (base class) smart pointers to the actual object of their derived class, and then call dynamic_cast to access the elements of the actual object
Instead of Method 1, set multiple smart pointers that point directly to different (derived classes) to point to the derived class object that you might want to use in a variety of depths "space becomes larger"
Instead of Method 2, use the base class to set an empty virtual function, "Sometimes it may not be very good"
4, if you can try not to use the transformation, especially in the efficiency of the code to avoid dynamic_cast, if the design needs to be transformed, try to change direction without transformation
5, if the transformation is necessary, try to hide him behind a function. The client can then call this function without having to put the transformation into their code.
6, the use of C + + new transformation, do not use old-fashioned, new classification to clear.
Effective C + + study notes clause 26-29