C++——代码风格

google代码风格

1.使用安全的分配器(allocator),如scoped_ptr,scoped_array

2.测试用的,其他的不能用:

  2.1 友元

  2.2 C++异常

  2.3 RTTI

3.类型转换,不要用(int)

  3.1 static_cast

  3.2 const_cast

  3.3 reinterpret_cast

  3.4 dynamic_cast

4.流用于日志,其他不要用(因为很容易用错类型)

5. 使用assertion声明变量,而非unsigned

6. 用于STL中,对于仿函数(functors)和特性(traits)可以不用class而用struct。其他一律用class

7.类

7.1 类成员有虚函数,析构函数为虚。(?)

7.2  重载操作符&的类不能被前置声明

7.3 尽量不要重载,而是用equals(),copyFrom()等替代

7.4 仿函数类

问题:

1.

猜你喜欢

转载自www.cnblogs.com/yrm1160029237/p/11321031.html