继承问题在程序最后,为啥xy不能继承
#include <iostream>using namespace std;
class Point
{
public:
//Point(int a,int b);
friend ostream & operator<<(ostream &output,Point &p );
void getxy();
int x,y;
};
/*Point::Point(int a,int b)
{
x=a;
y=b;
}*/
void Point::getxy()
{
cout<<"input x,y:"<<endl;
cin>>x>>y;
}
class Circle:public Point
{
public:
friend ostream & operator<<(ostream &output,Point &p );
//Circle(int a,int b,int r1);
int area();
void getr();
int r;
};
//Circle::Circle(int a,int b,int r1):Point(a,b),r(r1){}
void Circle::getr()
{
cout<<"input r:"<<endl;
cin>>r;
}
int Circle::area()
{
return 3.14*r*r;
}
class Cyinder:public Circle
{
public:
int h;
};
ostream & operator<<(ostream &output,Circle &C )
{
output<<C.x<<endl<<C.y<<endl<<C.area()<<endl;
return output;
}
ostream & operator<<(ostream &output,Point &p )
{
output<<p.x<<endl<<p.y<<endl;
return output;
}
int main()
{
Point o;
o.getxy();
cout<<o;//为啥有歧义,该怎样改呢
Circle c;
c.getr();
cout<<c;//为啥xy的值不能继承。该怎样改呢
return 0;
}