我都是用float定义的,为什么程序编译时会说从double到float截断。代码如下
#include
using namespace std;
//#define float double
class po
{
public:
po(float x=0,float y=0);
void setpo(float,float);
float getx()const{return x;}
float gety()const{return y;}
friend ostream & operator<<(ostream &,const po &);
protected:
float x,y;
};
po::po(float a, float b)
{
x=a;y=b;
}
void po::setpo(float a, float b)
{
x=a;y=b;}
ostream &operator<<(ostream &output,const po &p)
{
output<<"["<<p.x<<","<<p.y<<"]"<<endl;
return output;
}
int main()
{
po p(3.5,4.6);
cout<<"x="<<p.getx()<<",y="<<p.gety()<<endl;
p.setpo(8.5,6.8);
cout<<"p(new):"<<p<<endl;
}