重載运算符问题,为啥有歧义
#include <iostream>using namespace std;
class Point
{
public:
Point(int a,int b);
friend ostream & operator<<(ostream &output,Point &p );
void getxy();
public:
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<<"inpu 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(1,2);
o.getxy();
cout<<o;
Circle c(1,2,3);
c.getr();
cout<<c;
return 0;
}