Explanation of Google C ++ programming specifications
I personally think that google's C ++ coding standards are highly practical, and the code standards that come with Microsoft are simpler and clearer. I personally code them according to google's C ++ coding standards.
I. File Name
The file name must be in lowercase. It can contain underscores (_) or hyphens (-).
my_useful_class.ccmy-useful-class.ccmyusefulclass.cc
Ii. type commands
Type name: each word starts with an uppercase letter and does not contain underscores (_): MyExcitingClass or MyExcitingEnum.
All types of names-class, struct, type definition (typedef), enumeration-use the same conventions, for example:
// classes and structsclass UrlTable { ...class UrlTableTester { ...struct UrlTableProperties { ...// typedefstypedef hash_map
PropertiesMap;// enumsenum UrlTableErrors { ...
Iii. variable naming
All variable names are in lowercase, And the words are underlined and connected.
3.1. Name common variables
String table_name;
3.2. Name the class data member, ending with a line below
String name _;
3.3. structure data member name. It can be the same as a common member and does not end with an underscore like a class:
struct UrlTableProperties { string name; int num_entries;}
3.4. global variable name, prefixed with g _
String g_name;
3.5. Constant name, k followed by a word starting with an uppercase letter
Const int kDaysInAWeek = 7;
Iv. function name 4.1. A common function. The function name starts with an uppercase letter. Each word is capitalized and is separated by an underscore.
int AddTableEntry()bool DeleteUrl()
4.2. The access function must match the name of the accessed variable.
class MyClass {public:... int num_entries() const { return num_entries_; } void set_num_entries(int num_entries) { num_entries_ = num_entries; }private: int num_entries_;};
V. namespace
The namespace name is in all lowercase, and its name is based on the project name and directory structure: google_awesome_project
6. Enumeration naming
All the enumerated values are in uppercase, And the words are separated by the following strip. The enumerated names belong to the type, so the uppercase values are mixed:
enum UrlTableErrors { OK = 0, ERROR_OUT_OF_MEMORY, ERROR_MALFORMED_INPUT,};