关于基类成员的Google C ++样式指南

时间:2018-02-02 15:18:23

标签: c++ inheritance google-style-guide

Google C ++样式指南指出in the section about inheritance

  

将protected的使用限制为可能需要从子类访问的成员函数。请注意data members should be private

现在考虑以下情况:

class A {
    private:
         double m;
    // ...
}

class B : public A {
    // ...
}

我想正确的方法是A类为m实现getter / setter函数,以便B类可以访问它?

我真的不明白为什么选择此规则而不是使用protected数据成员。有人可以解释一下吗?

0 个答案:

没有答案
相关问题