| 實體 | 規則 | 正例 | 反例 |
|---|---|---|---|
| 類/結構體/枚舉/類型定義 | PascalCase | Line, SavingsAccount | line, savings_account |
| 變量/函數參數 | camelCase | line, savingsAccount | Line, line_width |
| 函數/方法 | 動詞 camelCase | getName(), computeTotalWidth() | GetName(), compute_total_width() |
| 常量/枚舉值 | UPPER_SNAKE_CASE | MAX_ITERATIONS, COLOR_RED | maxIterations, colorRed |
| 類私有成員 | camelCase + 下劃線後綴 | length_ | m_length, _length |
| 命名空間 | lowercase | model::analyzer | Model::Analyzer |
| 接口類 | I + PascalCase | IFoo | FooInterface |
| 模板參數 | 單大寫字母 | template<class T> | template<class Type> |
| 縮略語 | 按單詞大小寫 | exportHtmlSource() | exportHTMLSource() |
| 全局變量 | camelCase,用 :: 訪問 | ::mainWindow.open() | mainWindow.open() |
| 文件名 | lowercase .cpp/.h | line.cpp, line.h | Line.cpp |
#ifndef PROJECT_PATH_FILE_H_(跨平台優於 `#pragma once`)const char* 非 std::stringexplicitvirtual ~IFoo() {}scoped_ptr,容器用 shared_ptr,禁用 auto_ptrconst,輸出參數用指針static_cast/const_cast/reinterpret_cast/dynamic_cast(僅測試)constsizeof(var) 代替 sizeof(type)vectorvector/string 替代原始數組vector.data()/string.c_str()push_back// 註釋 風格@brief @param @return @author