私人成员派生类
来源:互联网 发布:网络播放量排行榜2016 编辑:程序博客网 时间:2024/06/10 01:17
前面的课程我们遗传的,我们已经让所有的公共数据成员为了简化的例子。在这一节,我们将谈论在遗传过程访问说明符的作用,以及ascover的不同类型遗传可能在C++。
这一点,你见过的私人和公共接入说明符,它确定谁能访问类的成员。有快速的环境,公众成员可以上网的人。私有成员只能由同一个类的成员函数访问。注意,这意味着不能访问私人成员派生类。
1234567class Base{private: int m_nPrivate; // can only be accessed by Base member functions (not derived classes)public: int m_nPublic; // can be accessed by anybody};
当处理继承类,事情有点复杂。
第一,有三分之一的访问说明符,我们还谈论因为它是唯一有用的遗传背景。受保护的访问说明符限制访问同一个类的成员函数,或派生类。
12345678910111213141516171819202122232425262728293031class Base{public: int m_nPublic; // can be accessed by anybodyprivate: int m_nPrivate; // can only be accessed by Base member functions (but not derived classes)protected: int m_nProtected; // can be accessed by Base member functions, or derived classes.}; class Derived: public Base{public: Derived() { // Derived's access to Base members is not influenced by the type of inheritance used, // so the following is always true: m_nPublic = 1; // allowed: can access public base members from derived class m_nPrivate = 2; // not allowed: can not access private base members from derived class m_nProtected = 3; // allowed: can access protected base members from derived class }}; int main(){ Base cBase; cBase.m_nPublic = 1; // allowed: can access public members from outside class cBase.m_nPrivate = 2; // not allowed: can not access private members from outside class cBase.m_nProtected = 3; // not allowed: can not access protected members from outside class}
0 0
- 私人成员派生类
- 派生类成员的访问
- 派生类成员的访问
- 派生类中的静态成员
- 派生类访问基类成员权限
- 派生类继承基类的成员
- 派生类中的成员初始化列表
- 派生类中引用保护成员
- 派生类的拷贝控制成员
- 成员函数被调用派生类对象!
- 派生类成员的标识与访问
- 派生类成员的访问属性
- C++基类指针与派生成员
- 区分“派生类对象”和“派生类”对基类成员的访问权限
- 派生类与派生类对象对基类成员的访问
- 派生类不继承基类的static成员
- 派生类成员对基类的访问
- 派生类初始化基类成员时的特殊问题
- 读取与创建配置文件
- iOS正则表达式
- Activity的启动和创建
- (迟到的博客,始终是一个过程)Linux/Unix环境下计算C程序运行时间
- mongodb的操作类,实现一写多读分离
- 私人成员派生类
- C++预处理指令
- Objective-C----内存管理--点语法
- CSDN博客积分规则
- 作业报告14 分数的累加
- 单链表实现学生成绩操作
- 将测试结果写到文件中
- c# 下载网页图片
- 如何查看android的wifi密码?究竟保存在哪里