1、#include包含“”和<>的使用
“”一般用做自定义好的.h文件
<>一般用做系统下的标准库文件的包含
虽然都能使用,但是这样方便阅读和追根溯源
2、namesapce定义命名空间放置
一般放在.cpp源文件的头部,一般.h头文件不需要实际使用;
3、项目名称一般小写表示
4、类成员中定义的变量书写规范
最后面加上_,如果是类对象前面加上m_,如果是其他类型变量,前面加上类型小写
m_class_= new Class();
bool bSatue_= true;
int iAdd_= 2;
float fPoint_=2.1;
double dPoint_=2.33;
string strChart_ ="aaa";
5、注释风格
函数声明注释
// @brief: 获取容器迭代器
// @param: void
// @ret: 返回容器迭代器
// @birth: created by Dablelv on 20180802
Iterator* getIterator() const;
函数定义注释:
// Divide result by two, taking into account that x contains the carry from the add.
for (int i = 0; i < result->size(); i++) {
x = (x << 8) + (*result)[i];
(*result)[i] = x >> 1;
x &= 1;
}
TODO注释
如果项目中存在功能代码有待修改和编写地方,建议使用TODO注释进行简略说明。TODO注释的作用类似于书签
// TODO(kl@gmail.com): Use a "*" here for concatenation operator.
// TODO(Zeke): change this to use relations.
// TODO(bug 12345): remove the "Last visitors" feature