Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4242737
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: C/C++

2011-04-20 09:02:59


  1. class Cfather
  2. {
  3. public:
  4.     void fatherskin();
  5. protected:
  6.     char name[];
  7. private:
  8.     int age;
  9. }


  10. class Cchild:public Cfather
  11. {
  12.  public:
  13.     void childskin();
  14.  private:
  15.     char ***;
  16. }

在继承类 继承基类时,有三种访问控制权限:

 public > protected > private




当访问权限设置为 public 时,基类中的,不变
  1. public:
  2.     void fatherskin();
  3. protected:
  4.     char name[];
  5. private:
  6.     int age;


当访问权限设置为 protected 时,基类中属性发生变化

  1. protected:
  2.     void fatherskin();
  3. protected:
  4.     char name[];
  5. private:
  6.     int age;

当访问权限设置为 private 时,基类中属性发生变化
  1. private:
  2.     void fatherskin();
  3. private:
  4.     char name[];
  5. private:
  6.     int age;


当访问权限设置好后,在继承类中,三种属性的特点:

1. public : 在 本类、继承类、类的对象可以访问

2. protected :本类、继承类 可以访问,类的对象不能访



3. private :本类 可以访问,继承类、类的对象不能访问


这里设置为 protected 的作用主要是:

        主要是用于 派生类 的使用





阅读(852) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~