c++ - 基类私有(private)成员属于派生类的哪一部分?

标签 c++ inheritance

class base {
    public:
        int getC() {return c;}
        int a;
    protected:
        int b;
    private:
        int c;
}

class derived: public base {
    public:
        int getD() {return d;}
    private:
        int d;
}

现在,派生类有公共(public)成员:

int getC() {return c;}
int getD() {return d;}
int a;

protected 成员: int b; 私有(private)成员: int d; 我无法确认 int c;是派生类的私有(private)成员。很明显 class derived 的任何新成员函数无法访问 c .所以,如果 cclass derived 的私有(private)成员, class derived 的成员函数应该有权访问 c .所以c是派生类的什么样的成员?

最佳答案

A derived class doesn't inherit access to private data members. However, it does inherit a full parent object, which contains any private members which that class declares.

看看这个question

关于c++ - 基类私有(private)成员属于派生类的哪一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45385969/

相关文章:

C++如何将 map 迭代器仅公开给 map 的值

各种类型指针的 C++ 容器

c++ - std::map 中的 std::pair 作为 const 返回

c++ - 实现细节继承?

c++ - 学习传承

java - JPA - InheritanceType.Joined 生成错误的表

c# - C# 中 C++ 1i64 移位的等效项是什么

c++ - 扩展动态分配的数组

c# - 将类的属性映射到接口(interface)

c++ - 在派生类的方法中使用基类的方法