"Effective C ++" Note 04 - Design and statement

Copyright: Creative Commons - Attribution - Share Alike (CC-BY-SA) https://blog.csdn.net/engrossment/article/details/88962096
  • Item 18 - Let interfaces easy to use correctly, can not easily be misused.
    • This is a big criteria, taking into account the specific needs of the correctness of interface design consistency, efficiency, encapsulation, ductility, and protocols.
    • "To promote the proper use" approach includes a coherent interface, and is compatible with the built-in types of behavior.
    • "Prevent misuse," the best way to include new types of restrictions on the type of operation, bound object values, and eliminating client resource management responsibilities.
  • Terms 19 - design class like the design type
    • This provision generally can be said is to design a new class (type) to meet compatible with the built-in types of behavior.
  • Terms 20-- ning with pass-by-reference-to-const pass-by-value replacement
    • To efficiently.
    • Trigger base class constructor can avoid passing a derived class object, situation inherited degradation occurs.
    • However, this provision does not apply to built-in types, STL iterators and function objects.
  • Terms 21 - When must return an object, do not imagine returns to its reference.
    • Previous terms apply to transfer to the main function, if it is returned from a function, use the reference probably a bad idea. Returns a pointer or reference to the implementation of the stack space that has been destroyed, it would inevitably lead to errors.
  • Terms of 22 - will be declared as private member variables
    • All the member variable life is private, can give customers access to data, the consistency of function calls, you can read and update subtle division, promised constraints guaranteed, class authors also sufficient to achieve flexibility.
  • Terms 23 - ning to non-member, non-friend function replacement member.
    • Possible, to take the non-member, non-friend function replaces the function member, may increase the encapsulation, and wrap the elastic performance scalability.
  • Item 24 - If all parameters type conversion units are required, please do this using non-member function.
    • ……
  • Item 25 - Consider not write a throw unusual swap function
    • ……

Terms of 24 and 25 did not really understand, need to carefully look at the back.

Liao Jieliang --2019-4-3

Guess you like

Origin blog.csdn.net/engrossment/article/details/88962096