7 宏定义常量 // naive:

define PI 3.14

1 2 // modern: const double PI = 3.14; 1 2 宏定义类型 // naive:

define uint unsigned int

1 2 // modern: typedef unsigned int uint; // or using uint = unsigned int; 1 2 3 宏定义函数 // naive:

define max(a, b) ((a)>(b)?(a):(b))

1 2 // modern: template inline T max(T a, T b) { return a>b? a: b; } 1 2 3 4 5 6 原生类型转换 // naive: int ival; double dval = (double)ival;

char pc1 = ...; const char cpc = (char )pc1; char pc2 = (const char *)cpc;

Derived pd1 = ...; Base pb = (Base )pd1; Derived pd2 = (Derived *)pb;

void pv1 = ...; long lval = (long)pv1; void pv2 = (void *)lval; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // modern: int ival; double dval = static_cast(ival);

char pc1 = ...; const char cpc = const_cast(pc1); char *pc2 = const_cast(cpc);

Derived pd1 = ...; Base pb = dynamic_cast(pd1); Derived *pd2 = dynamic_cast(pb);

void pv1 = ...; long lval = reinpreter_cast(pv1); void pv2 = reinpreter_cast(lval); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 线程 // naive: // #include pthread_t tid; pthread_create(&tid, func, arg); 1 2 3 4 // modern: // #include std::thread thr(func, arg); 1