DoxyGen一个把c++注释生成文档的工具
DoxyGen快速入门
谷歌C++风格指南
参考文章链接
# ifndef FOO_BAR_BAZ_H_
# define FOO_BAR_BAZ_H_
. . .
# endif
仅当函数较小(例如 10 个)时才定义内联函数 行或更少。 尽可能避免使用前置声明
struct B { } ;
struct D : B { } ;
# include "b.h"
void f ( B* ) ;
void f ( void * ) ;
void test ( D* x) { f ( x) ; }
非成员函数和静态成员函数在 某些情况。将非成员函数放入 命名空间可避免污染全局命名空间 C++允许您在函数中的任何位置声明变量。 我们鼓励您在本地范围内声明它们 可能,并且尽可能接近第一次使用
int i;
i = f ( ) ;
int i = f ( ) ;
int jobs = NumJobs ( ) ;
f ( jobs) ;
int jobs = NumJobs ( ) ;
f ( jobs) ;
禁止使用具有静态存储持续时间的对象 构造函数永远不应该调用虚函数 如果函数超过 40 行,请考虑 是否可以在不损害结构的情况下分解 命名规则
1. 文件名应全部小写,并且可以包含 下划线 () 或短划线 ()
2. 类型名称以大写字母开头,大写 每个新单词的字母,没有下划线
class UrlTable { . . .
class UrlTableTester { . . .
struct UrlTableProperties { . . .
typedef hash_map< UrlTableProperties * , std:: string> PropertiesMap;
using PropertiesMap = hash_map< UrlTableProperties * , std:: string> ;
enum class UrlTableError { . . .
3. 变量(包括函数参数)和数据成员的名称为(全部小写,单词之间带有下划线)。类的数据成员 (但不是结构)还具有尾随下划线
std:: string table_name;
class TableInfo {
. . .
private :
std:: string table_name_;
static Pool< TableInfo> * pool_;
} ;
struct UrlTableProperties {
std:: string name;
int num_entries;
static Pool< UrlTableProperties> * pool;
} ;
4. 声明的变量 或 ,其值为 固定 程序的持续时间,以前导“k”命名,后跟 通过混合大小写
const int kDaysInAWeek = 7 ;
const int kAndroid8_0_0 = 24 ;
5. 通常,函数应以大写字母开头,并具有 每个新单词的大写字母
AddTableEntry ( )
DeleteUrl ( )
OpenFileOrDie ( )
6. 枚举量
enum class UrlTableError {
kOk = 0 ,
kOutOfMemory,
kMalformedInput,
} ;
7. 宏定义,那么它们应该是 以所有大写字母和下划线以及特定于项目的前缀命名。
# define MYPROJECT_ROUND ( x) . . .
对临时代码使用注释, 一个短期的解决方案,或者足够好但不完美。TODO
if ( a == 0 )
if ( fabs ( a) < 1e-15 )
if ( p == nullptr )
if ( a)