求助:出现错误:warning C4305: 'argument' : truncation from 'const double' to 'float' er

具体错误:warning C4305: 'argument' : truncation from 'const double' to 'float'。
error C2593: 'operator <<' is ambiguous

源程序:
#include<iostream>
using namespace std;
class Point
{
public:
Point(float x=0,float y=0);
void setPoint(float,float);
float getX() const {return x;}
float getY() const {return y;}
friend ostream & operator<<(ostream &,const Point &);
protected:
float x;
float y;
};

Point::Point(float a,float b)
{
x=a;
y=b;
}

void Point::setPoint(float a,float b)
{
x=a;
y=b;
}

ostream & operator <<(ostream &output,const Point &p)
{
output<<"["<<p.getX()<<","<<p.getY()<<"]"<<endl;
return output;
}

int main()
{
Point p(3.5,6.4);
cout<<"x="<<p.getX()<<" "<<"y="<<p.getY()<<endl;
p.setPoint(8.0,10.5);
cout<<p<<endl;
return 0;
}

第1个回答  2011-05-10
类定义后面那分号改成英文的,main函数加上return 0;
相似回答