码迷,mamicode.com
首页 > 其他好文 > 详细

1.1

时间:2019-01-02 10:45:29      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:present   rate   temp   eric   com   code   ++   cti   type   

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. 

1.1

标签:present   rate   temp   eric   com   code   ++   cti   type   

原文地址:https://www.cnblogs.com/lefthook/p/10206770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!