关于多态还有虚函数的问题,求帮忙改正,谢谢
#include<iostream>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="<<x<<",y="<<y<<endl;
}
};
class Z1:protected X1
{
int z;
public:
Z1(int xx=0,int zz=0):X1(xx)
{ z=zz;}
void output()
{
cout<<"x="<<x<<",z"<<z<<endl;
}
};
int main()
{
X1 a(2);
Y1 b(3,4);
Z1 c(5,6);
X1*p[3]={&a,&b,&c};
for(itn i=0;i<3;i++)
{
p[i]->output();
}
return 0;
}
求帮忙改正