C++ 命名规范小结

1. #defines and const

test.h

#ifndef TEST_H
#define TEST_H
#endif
#define FALSE 0
#define TRUE (!FALSE)
#define MAX_NO_OF_STUDENT 100
const int MAX_NO_OF_STUDENT = 100;

2.Function(函数)

int m_iGetValues();
m_ : a member of a class
i  : returns a int
long m_lGetValues();
m_ : a member of a class
l  : returns a long 
int * m_piGetValus();
m_ : a member of a class
p  : returns pointer
i  : a int pointer
void * m_pvDoSomething();
m_ : a member of a class
p  : returns pointer
v  : a void pointer
unsigned char ucGetValues();
uc : This returns unsigned char
bool bIsRunning();
b : returns a bool 
void m_vSetValues(int iNum);
m_ : a member of a class
v  : there is no return value

If the function is not a member of a class, then ‘m_’ prefix is not used.Example:

//global function
int g_iGetValues();
g_ : a global functions 
i  : returns a int

3.Variables(变量)

//在 int变量 的最前面加上一个小写的i,之后每个单词的第一个字母大写
int iNum;
int iNoOfVariables;
//在数组的最前面加上a(array),然后紧接着一个数组类型的字母。
char acFileName[128];  ac代表一个字符类型的数组
int aiNum[128];  ai代表这是一个int类型的数组
char *apcFileName[128];  这是一个数组,数组中保存着128个char类型的指针
char (*pacFileName)[128];  这是一个指针,
//在变量的最前面加上 m_, 代表这是一个类或者是一个结构体中的成员变量。
typedef struct _SNode {
    char * m_pcName;  //m_:结构体成员; pc:指向char类型的指针
    struct _SNode * m_pstNext;  //m_结构体成员; pst:指向struct类型的指针
}SNode;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值