1.1

Effective C++ Scott Meyers

Chapter 7. Templates and Generic Programming

1. Item 41: Undetstand Implicit interfaces and compile-time polymorphism

  Both classes and templates support interfaces and polymorphism.

  For classes, interfaces are explicit and centered on function signatures. Polymorphism occures at runtime through virtual functions.

  For template parameters, interfaces are implicit and based on valid expressions. Polymorphism occurs during compilation through template instantiation and function overloading resolution.

2. Item 42: Understand the two meanings of typename.

  When declaring template parameters, class and typename are interchangeable.

  Use typename to identify nested dependent type names, except in base class lists or as a base class identifier in a member initialization list.

3. Item 43: Know how to access names in templatized base class.

  In derived class templates, refer to names in base class templates via a "this->" prefix, via using declarations, or via an explicit base class qualification.

4. Item 44: Factor parameter-independent code out of templates.

  Templates generate multiple classes and multiple functions, so any template code not dependent on a template parameter causes bloat.

  Bloat due to non-type template parameters can  often be eliminated by replacing template parameters with function parameters or class data members.

  Bloat due to type parameters can be reduced by sharing implementations for instantiation types with identical binary representations. 

posted @ 2019-01-02 02:45  lefthook  阅读(299)  评论(0编辑  收藏  举报