本文总结一些编程部分好的编程规范
空格出现在','之后,不作为结束符的';'之后,"?" ":" 前后,各种二元运算符之后
int Func1(int nA, int nB);
for(int nCnt = 0; nCnt <= 100; nCnt++)...
if(nYear <= 2012)...
if((a <= b) && (c <= d))...
nX = a > b ? 10 : 20;
2 长表达式
表达式过长可以在低优先级处拆分多行,新行要进行适当的缩进
if( (very_long_variable1 >= very_long_variable2)
&& (very_long_variable3 <= very_long_variable4)
&& (very_long_variable5 >= very_long_variable6) )
3 指针定义数据
int* nY, nZ;会被误认为定义了两个整型指针可以用typedef避免
typedef int* PINT;
PINT p1, p2;这里就是定义了两个整型指针
4 多层嵌套的注释
在一些段落结束的地方加注释
if()
{
...
while(...)
{
...
}//end of while
...
}//end of if
5 类的编写顺序
一般先写接口,把一些私有数据成员放在后面
class A
{
public:
void Func1();
void Func2();
private:
int m_nA;
int m_nB;
};