根據多年工作經驗和其它命名規范整理而成,個人感覺比較規范的標准,現應用於我的開發團隊。
c++文件應以.cpp,頭文件以.h結尾,文件名全部小寫,文件名和類名相同。
舉例:
publictools.h
publictools.cpp
類型包括:類(class)、結構體(struct)、類型定義(typedef)、枚舉(enum)等。
類型名稱每個單詞首字母大寫。
舉例:
類(class):
class TestClass
{
};
結構體(struct):
struct TestStruct
{
};
類型定義(typedef):
typedef struct TestType
{
};
枚舉(enum):
enum TestEnum
{
};
普通變量首字母小寫,成員變量以_結尾,函數參數以_開頭。全局變量g_開頭,靜態變量s_開頭。
舉例:
普通變量:
int index;
char type;
string name;
成員變量:
int index_;
函數參數
void SetIndex(int _index)
{
};
全局變量:
int g_count;
靜態變量
int s_number;
全大寫,單詞間用_分開。
舉例:
const string MAX_FILENAME255;
首字母大寫,取值與設值函數與變量名匹配。
舉例:
int index_;
int GetIndex()
{
returnindex_;
};
void SetIndex(int _index)
{
index_ =_index;
};
全小寫字母。
舉例:
namespace myNamespace
{
};
首單詞全寫,次單詞首字母大寫。
舉例:
struct TestStruct
{
int number,
string studentName
};
enum TestEnum
{
errorIn,
errorOut
};
全大寫,單詞間用_分開。
舉例:
#define PI_RAUD3.14159265
全大寫。
舉例:
#ifndef FOO_BAR_BAZ_H_
#define FOO_BAR_BAZ_H_
...
#endif // FOO_BAR_BAZ_H_;