Is using underscore suffix for members beneficial?

后端 未结 13 2069
猫巷女王i
猫巷女王i 2020-12-29 03:58
class C {
 private:
  int member_; // here is the underscore I refer to.
}

This underscore is recommended by Google Style Guide and Geosoft\'s C++

13条回答
  •  有刺的猬
    2020-12-29 04:50

    Well since no one mentioned it: adding an underscore to member variable allows you to name your getter and setter with the 'conceptual' name of the variable.

    ex:

    class MyClass
    {
       int someMember_;
    
    public:
       int someMember() const { return someMember_; }
       void someMember( int newValue ) { someMember_ = newValue; }
    };
    

    not that I use this style though.

提交回复
热议问题