继承的权限问题..

上一篇 / 下一篇  2007-11-25 15:04:00 / 个人分类:c++

非常简单...即:双重权限...

                           public               protected           private

 public               public               protected           private   

protected          protected         protected           private   

private               private              private                private   

 

// 继承的访问权限.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

class BaseEntity
{
public:
 int b1;
protected:
 int b2;
private:
 int b3;
};
////
class D1:public BaseEntity
{
public:
 void test()
 {
  b1 = 10;
  b2 = 20;
  b3 = 30;
 }
};
/*///
class D11:public D1
{
 void test()
 {
  b1 = 5;
  b2 = 6;
  b3 = 7;
 }
};
////
class D2:private BaseEntity
{
public:
 void test()
 {
  b1 = 8;
  b2 = 9;
  b3 = 10;
 }
};
////
class D22:public D2
{
public:
 void test()
 {
  b1 = 11;
  b2 = 12;
  b3 = 13;
 }
};
////
class D3:public BaseEntity
{
public:
 void test()
 {
  b1 = 14;
  b2 = 15;
  b3 = 16;
 }
};
////
class D33:public D3
{
public:
 void test()
 {
  b1 = 17;
  b2 = 18;
  b3 = 19;
 }
};
///*/
int _tmain(int argc, _TCHAR* argv[])
{
 D1 d;
 d.b1 = 1;
 d.b2 = 2;
 d.b3 = 3;

/*
 D11 d1;
 d1.b1 = 1;
 d1.b1 = 2;
 d1.b3 = 3;

 D22 d2;
 d2.b1 = 4;
 d2.b2 = 5;
 d2.b3 = 6;

 D33 d3;
 d3.b1 = 7;
 d3.b2 = 8;
 d3.b3 = 9;
*/
 getchar();
 return 0;
}

//有什么不明白的...自己调试吧..


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar