/***C++面向对象程序设计*********************/
/***继承性与派生类 2013 10 28***************/
#include
#include
////////基类A
class A
{
private: int x1;
public:
A()
{
x1=0;
cout<<"A Constructor1-1"<
}
A(int i)
{
x1=i;
cout<<"A Constructor2-1"<
}
void disp()
{
cout<<"x1="<
}
};
////////基类B
class B
{
private: int x2;
public:
B()
{
x2=0;
cout<<"B Constructor1-2"<
}
B(int i)
{
x2=i;
cout<<"B Constructor2-2"<
}
void disp()
{
cout<<"x2="<
}
};
////////派生类C继承于A
class C:public A
{
private:
int x3;
B b1;
public:
C()
{
x3=0;
cout<<"C Constructor1-3"<
}
C(int x,int y,int z):A(x),b1(y)
{
x3=z;
cout<<"C Constructor2-3"<
}
void disp()
{
A::disp();
b1.disp();
cout<<"x3="<
}
};
////////////////////
void main()
{
C c1;
c1.disp();
C c2(1,2,3);
c2.disp();
}
JC1.jpg
JC2.jpg
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27660822/viewspace-775232/
,如需转载,请注明出处,否则将追究法律责任。