Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1498188
  • 博文数量: 329
  • 博客积分: 2773
  • 博客等级: 少校
  • 技术积分: 4219
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:17
个人简介

淡定从容,宁静致远

文章分类

全部博文(329)

文章存档

2016年(4)

2015年(50)

2014年(68)

2013年(45)

2012年(162)

分类: C/C++

2012-12-18 22:01:40

#include
using namespace std;
class A
{
 protected:
  int x;
  int y;
 public:
  static int z;
 public:
  void setA(int x1,int y1)
  {
  // cout<<"sizeof(*this)="<
//   cout<<"this="<   x=x1;
   y=y1;
  
  }
  void printA()
  {
   cout<<"x="<  
   cout<<"y="<
 //  cout<<"sizeof(*this)="<   
 //  cout<<"this="<  }
  A()
  {
  
   cout<<"A无参构造函数"<  
  }
  ~A()
  {
  
   cout<<"A析构"<  }
  A(int x1,int y1)
  {
   x=x1;
   y=y1;
  
   cout<<"A有参构造函数"<  }
};
int A::z=0;
class B:protected A
{
 public:
  int m;
  int n;
  A a;
  void setB(int m1,int n1)
  {
     x=1000;
   y=2000;
   m=m1;
   n=n1;
   setA(100,200); 
   cout<<"sizeof(*this)="<
   cout<<"this="<  
  }
  void printB()
  {
   printA();
   cout<<"m="<  
   cout<<"n="<
   //cout<<"sizeof(*this)="<
  // cout<<"this="<  }
  B()
  {
  
   cout<<"B无参构造函数"<  }
  B(int x1,int y1,int m1,int
    n1):A(x1,y1)
  {
   m=m1;
   n=n1;
   
   cout<<"B有参构造函数"<  
  }
  ~B()
  {
  
   cout<<"B析构"<  }
};
class C:protected B
{
 public:
  void printC()
  {
   x=100;
   printA();
  
  }

};
int main()
{
// A a;
 B b(100,200,300,400);
 b.printB();
// b.setA(100,200);
// b.printA();
// b.setB(100,2000);
// b.printB();
// cout<<"&b="<<&b< cout<<"sizeof(B)="<
// b.setB(500,600);
// b.printB();
// cout<<"&a.z="<<&a.z<
// cout<<"&b.z="<<&b.z<
// b.set(100,200);
// b.print();
// cout<<"sizeof(b)="</* cout<<"&b.x="<<&b.x<
 cout<<"&b.y="<<&b.y< cout<<"&b.m="<<&b.m< cout<<"&b.n="<<&b.n<
 cout<<"&b"<<&b<// cout<<"sizeof(A)="< 
// cout<<"sizeof(B)="< return 0;
}
阅读(1259) | 评论(0) | 转发(1) |
0

上一篇:多继承

下一篇:类和对象

给主人留下些什么吧!~~