#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;
}
阅读(1300) | 评论(0) | 转发(1) |