问题描述
- #c++#求大神帮我改正下,关于多态和虚函数的
-
#include
using namespace std;
class X1
{
protected:
int x;
public:
X1(int xx){x=xx;}
virtual void output()=0;
};
class Y1:private X1
{
int y;
public:
Y1(int xx=0,int yy=0):X1(xx)
{y=yy;}
void output()
{
cout<<"x="<
}
};
class Z1:protected X1
{
int z;
public:
Z1(int xx=0,int zz=0):X1(xx)
{ z=zz;}
void output()
{
cout
}
};
int main()
{
X1 a(2);
Y1 b(3,4);
Z1 c(5,6);
X1*p[3]={&a,&b,&c};
for(itn i=0;i
{
p[i]->output();
}
return 0;
}
时间: 2024-09-29 13:15:29