The benefits of using underscore function naming in C include: enhancing readability, avoiding name conflicts, and clarifying function usage. Syntax: identifier_function name (parameter list). Convention: A single underscore indicates a private or protected function, a double underscore indicates a static function, and a triple underscore indicates an implementation detail. For example, in the Student class, the private function get_name() can be renamed to _get_name() to distinguish it from the public function.
Underscore nomenclature for C function naming
In C, using underscore nomenclature for function naming has many benefits:
Syntax:
标识符_函数名(参数列表)
Convention:
Practical case:
Suppose we have a Student
class, which contains a class named get_name()
of functions:
class Student { public: std::string get_name() { return name; } private: std::string name; };
Using underscore nomenclature, we can rename the private function to _get_name()
:
class Student { public: std::string get_name() { return _get_name(); } private: std::string _get_name() { return name; } };
In this way, we can distinguish the public get_name()
function and the private _get_name()
function.
Tip:
The above is the detailed content of Underscore nomenclature for C++ function naming. For more information, please follow other related articles on the PHP Chinese website!