Hungarian nomenclature is a C naming convention that specifies type information for variables, functions, and types by using prefixes (indicating types) and suffixes (indicating usage). Its advantages include high readability, ease of debugging and maintenance. The disadvantages are that it is lengthy, visually cluttered, and potentially ambiguous, so it needs to be used with caution.
Hungarian notation is a naming convention for specifying variables, functions, and Type information for the type. This convention uses a prefix to indicate the type of data and a suffix to indicate the purpose or intent of the data.
Prefix | Type |
---|---|
# #m_
| Member variable|
i_
| Integer|
f_
| Floating point number|
sz_
| Size|
p_
| Pointer|
obj_
| Object|
arr_
| array|
string | |
Boolean value |
Use | |
---|---|
Input parameters |
|
Output parameters |
|
Helper function |
|
Value function |
|
Set value function |
|
Create function |
|
Destruction function |
class Person { public: Person(const std::string& name, int age); void PrintInfo() const; private: std::string m_name; int m_age; };
Use Hungarian nomenclature, The constructor and member functions of this class can be rewritten as:
class Person { public: Person(const std::string& str_Name, int i_Age); void PrintInfo() const; private: std::string m_name; int m_age; };
Advantages
The above is the detailed content of Hungarian notation for C++ function naming. For more information, please follow other related articles on the PHP Chinese website!