C++——命名规范

来源:互联网 发布:廖雪峰python教程微盘 编辑:程序博客网 时间:2024/05/17 22:28

需求分析:

大都命名都根据公司自己的统一标准就行,没有统一标注,就可以按照下面比较通用的标准



解决方案:

1.变量
1.1 全局变量

int glbO_nCounts;  //或者可以更简化  int g_nObjectCounts;

1.2 成员变量

class CTest{    // ...    // 普通成员变量    int m_nCounts;    // 静态成员变量    static int sm_nCount;};

1.3 宏定义,常量

#define MAX_GROUPSIZE  1000    // 全部使用大写const int MAX_VALUE = 300;     // 全部使用大写

1.4 静态局部变量

void Function(){    static int _MAX_VALUE = 0;    // 使用带下滑线的全大写字母}



2.函数
2.1 全局函数

int glbf_GetCounts();  //或者简化形式  int g_GetCount();

2.2 成员函数

class CTest{public:    int GetValue() const;    // 简单明了即可protected:    int _GetValue() const;   // 可以用下化替代,也可以使用上面的private:    int __GetValue() const;  // 只供自己使用的private类型,也可以使用上面的};
1 0
原创粉丝点击