EC读书笔记系列之17:条款41、42、43、44、45、46
条款 41 了解隐式接口与编译器多态 记住: ★classes和templates都支持接口和多态 ★对classes而言接口是显式的(explicit),以 函数签名 为中心。多态则是通过virtual函数发生于 运行期 ★对templates而言,接口是隐式的(implicit),奠基于 有效表达式 。多态则是通过 template 具现化 和 函数重载解析 发生于 编译期 条款 42 了解 typename 的双重意义 记住: ★声明template参数时,前缀关键字class和typename可互换( 函数模板或类模板均可 !!!) ★请使用关键字typename标识 嵌套从属类型名称 ;但不得在base class lists或成员初始列内以它作为base class修饰符 --------------------------------------------------------------------- template< class T> class Widget; template< typename T> class Widget; 两者是等效的 ---------------------------- 但有时一定得使用typename: template<typename C> void print2nd( const C& container ) {