相关疑难解决方法(0)

C++ getters/setters编码风格

我已经在C#中编程了一段时间,现在我想要提高我的C++技能.

上课:

class Foo
{
    const std::string& name_;
    ...
};
Run Code Online (Sandbox Code Playgroud)

什么是最好的方法(我只想允许对name_字段的读访问):

  • 使用getter方法: inline const std::string& name() const { return name_; }
  • 让这个领域公开,因为它是一个常数

谢谢.

c++ coding-style getter-setter

65
推荐指数
5
解决办法
17万
查看次数

标签 统计

c++ ×1

coding-style ×1

getter-setter ×1