码迷,mamicode.com
首页 > 编程语言 > 详细

C++编程命名规范

时间:2014-06-12 16:23:58      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:class   blog   http   com   get   文件   

原地址:http://www.cnblogs.com/joinclear/archive/2013/02/21/2921422.html
C++编程命名规范
0前言

 根据多年工作经验和其它命名规范整理而成,个人感觉比较规范的标准,现应用于我的开发团队。

1命名通用规则
文件名、函数名、变量名命名应具有描述性,不要过度的缩写,类型变量是名词,函数名是动词或动词+名词。函数名必须是指令性的,非常普遍性的才用缩写。
2文件命名

c++文件应以.cpp,头文件以.h结尾,文件名全部小写,文件名和类名相同。

举例:

publictools.h

publictools.cpp

3类型命名

类型包括:类(class)、结构体(struct)、类型定义(typedef)、枚举(enum)等。

类型名称每个单词首字母大写。

举例:

类(class):

class TestClass

{

};

结构体(struct):

struct TestStruct

{

};

类型定义(typedef):

typedef struct TestType

{

};

枚举(enum):

enum TestEnum

{

};

4变量命名

普通变量首字母小写,成员变量以_结尾,函数参数以_开头。全局变量g_开头,静态变量s_开头。

举例:

普通变量:

int index;

char type;

string name;

成员变量:

int index_;

函数参数

void SetIndex(int _index)

{

};

全局变量:

int g_count;

静态变量

int s_number;

5常量命名

全大写,单词间用_分开。

举例:

const string MAX_FILENAME255;

6函数命名

首字母大写,取值与设值函数与变量名匹配。

举例:

int index_;

int GetIndex()

{

returnindex_;

};

void SetIndex(int _index)

{

index_ =_index;

};

7名字空间

全小写字母。

举例:

namespace myNamespace

{

};

8类型体命名

首单词全写,次单词首字母大写。

举例:

struct TestStruct

{

int number,

string studentName

};

enum TestEnum

{

errorIn,

errorOut

};

9宏命名

全大写,单词间用_分开。

举例:

#define PI_RAUD3.14159265

10#define头文件保护命名

全大写。

举例:

#ifndef FOO_BAR_BAZ_H_

#define FOO_BAR_BAZ_H_

...

#endif // FOO_BAR_BAZ_H_;

C++编程命名规范,布布扣,bubuko.com

C++编程命名规范

标签:class   blog   http   com   get   文件   

原文地址:http://www.cnblogs.com/lanye/p/3781982.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!