现在的位置: 首页 > 综合 > 正文

Effective C++学习笔记(三)

2015年01月14日 ⁄ 综合 ⁄ 共 426字 ⁄ 字号 评论关闭

条款02—— Prefer consts, enums, and inlines to #defines(宁可以编译器替换预处理器)

一、  The enum hack

       

二、  inline

        函数宏:

       // 以a和b的较大值调用f

       #define CALL_WITH_MAX(a, b)    f((a) > (b) ? (a) : (b))

 

       template <typename T>  // 由于我们不知道T是什么,所以采用pass by reference to const

       inline  void callWithMax(const T& a, const T& b)

       {

            f(a > b ? a : b);

       }

 

抱歉!评论已关闭.