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;

4.總結

具體代碼參考連接:http://mdgsf.xyz/?p=31指針

相關文章
相關標籤/搜索