主题:改错
#include <iostream.h>
class X{
public:
X(int x)
{a=x;}
void showX( )
{cout<<"a="<<a<<endl;}
private:
int a;
};
class Y: private X{
public:
Y(int x,int y):X(x)
{b=y;}
void showY( )
{ showX();
cout<<"b="<<b<<endl;
}
private:
int b;
};
class Z: public Y{
public:
Z(int x, int y,int z):Y(x,y)
{ c=z; }
void showZ( );
private:
int c;
};
void Z::showZ()
{showY();
cout<<"c="<<c<<endl;
};
int main( )
{
Z obj(10, 20, 30);
obj.showX( );
obj.showY( );
obj.showZ( );
return 0;
}
要求: Y是X的私有继承,Z是Y的公有继承
输出 a=10
a=10
b=20
a=10
b=20
c=30
多谢
class X{
public:
X(int x)
{a=x;}
void showX( )
{cout<<"a="<<a<<endl;}
private:
int a;
};
class Y: private X{
public:
Y(int x,int y):X(x)
{b=y;}
void showY( )
{ showX();
cout<<"b="<<b<<endl;
}
private:
int b;
};
class Z: public Y{
public:
Z(int x, int y,int z):Y(x,y)
{ c=z; }
void showZ( );
private:
int c;
};
void Z::showZ()
{showY();
cout<<"c="<<c<<endl;
};
int main( )
{
Z obj(10, 20, 30);
obj.showX( );
obj.showY( );
obj.showZ( );
return 0;
}
要求: Y是X的私有继承,Z是Y的公有继承
输出 a=10
a=10
b=20
a=10
b=20
c=30
多谢