布尔表达式:如果一个布尔表达式超过标准行宽,断行方式要统一一下.
下例中,逻辑与(&&)操作符总位于行尾:
if (this_one_thing > this_other_thing &&
a_third_thing == a_fourth_thing &&
yet_another & last_one) {
...
}注意,上例的逻辑与(&&)操作符均位于行尾.可以考虑额外插入圆括号,合理使用的话对增强可读性是很有帮助的.
函数返回值:return表达式中不要用圆括号包围.
函数返回时不要使用圆括号:
return x; // not return(x);变量及数组初始化:用=或()均可.
在二者中做出选择;下面的方式都是正确的:
int x = 3;
int x(3);
string name("Some Name");
string name = "Some Name";预处理指令:预处理指令不要缩进,从行首开始.
即使预处理指令位于缩进代码块中,指令也应从行首开始.
// Good - directives at beginning of line
if (lopsided_score) {
#if DISASTER_PENDING // Correct -- Starts at beginning of line
DropEverything();
#endif
BackToNormal();
}
Warning:
// Bad - indented directives
if (lopsided_score) {
#if DISASTER_PENDING // Wrong! The "#if" should be at beginning of line
DropEverything();
#endif // Wrong! Do not indent "#endif"
BackToNormal();
}
类格式:访问控制块的声明依次序是public:,protected:,private:,每次缩进1个空格.
类声明(对类注释不了解的话,参考类注释)的基本格式如下:
class MyClass : public OtherClass {
public: // Note the 1 space indent!
MyClass(); // Regular 2 space indent.
explicit MyClass(int var);
~MyClass() {}
void SomeFunction();
void SomeFunctionThatDoesNothing() {
}
void set_some_var(int var) { some_var_ = var; }
int some_var() const { return some_var_; }
private:
bool SomeInternalFunction();
int some_var_;
int some_other_var_;
DISALLOW_COPY_AND_ASSIGN(MyClass);
};注意事项:
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-35033-27.html
检查
叫兽
那里的岛礁有许多在自然状况下是当涨潮时处于海面以下的