Is using underscore suffix for members beneficial?

后端 未结 13 2222
猫巷女王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:45

    This is basically a religious argument so you're never going to reach a consensus on this style. FWIW, I use this style for my member variables for reasons already stated by others, e.g.:

    class Foo
    {
    public:
      Foo(std::string name, int age) :
        name_(name),
        age_(age)
      {
      }
    
      std::string name() const { return name_; }
      void name(const std::string& name) { name_ = name; }
    
      int age() const { return age_; }
      void age(int age) { age_ = age; }
    private:
      std::string name_;
      int age_;
    };
    

    Just adopt something you're happy with and stick with it.

提交回复
热议问题