IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Naming Conventions for Accessors

    金庆发表于 2022-09-22 08:02:00
    love 0

    Naming Conventions for Accessors

    from: C++ Programming Guidelines (cginternals.github.io)

    When naming accessors within classes, non-trivial getters and queries, i.e., those that perform calculations, you should prepended get. All other getters have no prefix and setters have the set prefix.

    class Object
    {
    public:
      int radius() const;
      void setRadius(int value);

      int getPerimeter();

    private:
      int m_radius;
    };

    int Object::radius() const
    {
        return m_radius;
    }

    void Object::setRadius(int value)
    {
        m_radius = value;
    }

    int Object::getPerimeter()
    {
        return 2 * pi * m_radius;
    }


    金庆 2022-09-22 16:02 发表评论


沪ICP备19023445号-2号
友情链接