从平面点类派生出空间点类,父类中有重载的构造函数
class point_2D
{
protected:
int x,y;
public:
point_2D()
{
x=0;
y=0;
}
point_2D(int xx,int yy)
{
x=xx;
y=yy;
}
};
class point_3D :public point_2D
{
protected:
int z;
public:
point_3D()
{
z=0;
}
point_3D(int xx,int yy):point_2D(xx,yy)
{
z=0;
}
point_3D(int xx,int yy,int zz):point_2D(xx,yy)
{
z=zz;
}
void output()
{
cout<<x<<endl;
cout<<y<<endl;
cout<<z<<endl;
cout<<"***************"<<endl;
}
};
int main()
{
point_3D p1;
point_3D p2(3,4);
point_3D p3(1,2,3);
p1.output();
p2.output();
p3.output();
}