1. Header files should be self-contained.
  2. All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be <PROJECT>_<PATH>_<FILE>_H_.
  3. You may forward declare ordinary classes in order to avoid unnecessary #includes. A "forward declaration" is a declaration of a class, function, or template without an associated definition. #include lines can often be replaced with forward declarations of whatever symbols are actually used by the client code.
  4. Use standard order for readability and to avoid hidden dependencies: Related header, C library, C++ library, other libraries' .h, your project's .h.
    • dir2/foo2.h.
    • C system files.
    • C++ system files.
    • Other libraries' .h files.
    • Your project's .h files.
  5. In dir/foo.cc or dir/foo_test.cc, whose main purpose is to implement or test the stuff in dir2/foo2.h, order your includes as follows:
  6. Do not make nested classes public unless they are actually part of the interface, e.g., a class that holds a set of options for some method.
  7. Variables needed for if, while and for statements should normally be declared within those statements, so that such variables are confined to those scopes. E.g.:
  8. while (const char* p = strchr(str, '/')) str = p + 1;
  9. Constructors should never call virtual functions or attempt to raise non-fatal failures. If your object requires non-trivial initialization, consider using a factory function or Init() method.
  10. Use the C++ keyword explicit for constructors callable with one argument.
  11. Use delegating and inheriting constructors when they reduce code duplication.
  12. Inheriting constructors allow a derived class to have its base class's constructors available directly, just as with any of the base class's other member functions, instead of having to redeclare them. This is especially useful if the base has multiple constructors.
  13. Only very rarely is multiple implementation inheritance actually useful. We allow multiple inheritance only when at most one of the base classes has an implementation; all other base classes must be pure interface classes tagged with the Interface suffix. Multiple inheritance allows a sub-class to have more than one base class. We distinguish between base classes that are pure interfaces and those that have an implementation.
  14. All parameters passed by reference must be labeled const.
  15. Use streams only for logging.
  16. Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.
  17. document that a variable is non-negative using assertions. Don't use an unsigned type.
  18. The names of variables and data members are all lowercase, with underscores between words. Data members of classes (but not structs) additionally have trailing underscores. For instance: a_local_variable, a_struct_data_member, a_class_data_member_. Data members of structs, both static and non-static, are named like ordinary nonmember variables. They do not have the trailing underscores that data members in classes have.
  19. There are no special requirements for global variables, which should be rare in any case, but if you use one, consider prefixing it with g_ or some other marker to easily distinguish it from local variables.
  20. Regular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(), MyExcitingMethod(), my_exciting_member_variable(), set_my_exciting_member_variable().
  21. Use a k followed by mixed case, e.g., kDaysInAWeek, for constants defined globally or within a class.const int kDaysInAWeek = 7;
  22. Enumerators should be named either like constants or like macros: either kEnumName or ENUM_NAME.
  23. Empty loop bodies should use {} or continue, but not a single semicolon.
  24. both of the && logical AND operators are at the end of the line.

摘自:http://google-styleguide.googlecode.com/svn/trunk/cppguide.html

关于c++风格 code style的更多相关文章

  1. intelij IDEA设置goole code style风格

    1.安装google-java-format 插件      file ->Setings... ->pligins     输入上诉插件安装 2.下载IntelliJ Java Goog ...

  2. Java Code Style

    近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...

  3. 与你相遇好幸运,The Moe Node.js Code Style Guide

    The Moe Node.js Code Style Guide  By 一个最萌的开发者 @2016.9.21 >>代码是人来阅读的,格式规范的代码是对编程人员最好的礼物 :) > ...

  4. Eclipse setting Java code style and codetemplate

    1.open the eclipse tool window First click the Window menu,then check the children's menu which name ...

  5. 【Idea】idea code style配置eclipse code formatter

    在eclipse中有自动配置code style的功能 ,但是idea上却没有,这个时候需要自己手工配置 1. 在idea中找到Preference->Plugins->Browse re ...

  6. checkstyle.xml Code Style for Eclipse

    1. Code Templates [下载 Code Templates] 打开 Eclipse -> Window -> Preferences -> Java -> Cod ...

  7. _rqy's Code Style for OI

    _rqy's Code Style for OI Inspired by Menci's Code Style for OI 本文介绍_rqy的OI中的代码规范.其来源主要为_rqy的长期积累及参考G ...

  8. Javascript Code Style Guide

    本指南采用的Airbnb发布的基于ES5的JavaScript Code Style. ES5 英文版:https://github.com/airbnb/javascript/tree/es5-de ...

  9. 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键

    google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...

随机推荐

  1. I Hate It(线段树基础)

    Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  2. Flume内存溢出错误

    java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:) at java.lang.Ab ...

  3. .net接口开发远程调试

    第一步: 找到你的C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Remote Debugger\x64\msvsmon ...

  4. 用R进行市场调查和消费者感知分析

    // // 问题到数据 理解问题 理解客户的问题:谁是客户(某航空公司)?交流,交流,交流! 问题要具体 某航空公司: 乘客体验如何?哪方面需要提高? 类别:比较.描述.聚类,判别还是回归 需要什么样 ...

  5. aspx与ashx

    ashx在VS的中文版是新建“一般处理程序”,其实是一个实现类System.Web.IHttpHandler接口的类.而任何一个实现了IHttpHandler接口的类都能作为一个外部请求的目标程序.H ...

  6. 关于netstat

    netstat 命令是 linux 下一个非常有用的命令,顾名思义,其作用是查询当前的网络状态. 以最常用的查询 TCP 连接状态为例 netstat -an|awk '/tcp/ {print $6 ...

  7. IOS学习笔记25—HTTP操作之ASIHTTPRequest

    IOS学习笔记25—HTTP操作之ASIHTTPRequest 分类: iOS2012-08-12 10:04 7734人阅读 评论(3) 收藏 举报 iosios5网络wrapper框架新浪微博 A ...

  8. UIView 的属性opaque详解

    该属性用法决定与该消息的接受者是否让其视图透明. 该属性的用处在于:给绘图系统提供一个性能优化开关. 当该值设计为YES,那么绘图系统会把它当作不透明看待,那么在执行绘图的时候会优化绘图一些操作,并且 ...

  9. FFT 模板

    #include<bits/stdc++.h> #define ll long long #define N 600005 using namespace std; inline int ...

  10. 使 Excel 规则更容易理解(Oracle Policy Modeling-Make your Excel rules easier to understand)

    有以下几种方法可以使 Excel 规则更容易理解. 在 Excel 工作簿中缩短属性名称 您可以使用图例关键字创建在 Excel 中引用属性的缩写方式.可以根据情况指定此缩写形式. 要指定图例关键字, ...