c++语意错误 error C2440: 'initializing' : cannot convert from '' to 'float'
#include<iostream.h>classPoint{private:floatx;floaty;public:Point(floatx,floaty){this...
#include <iostream.h>
class Point
{private:
float x;
float y;
public:
Point(float x,float y)
{this->x=x;
this->y=y;
}
Point(Point &t):
x(t.x),y(t.y)
{
}
~Point(void)
{}
void setx(float x)
{this->x=x;
}
void sety(float y)
{this->y=y;
}
float Getx(void) const
{return x;
}
float Gety(void) const
{return y;
}
};
class Line
{ private:
Point first;
Point last;
public:
Line(Point &a,Point &b) :
first(a),last(b)
{
}
Line(float a,float b,float c,float d):
first(a,b),last(c,d)
{
}
~Line(void)
{}
void getline(void)
{ cout<<"起始点为: ("<<first.Getx()<<","<<first.Gety()<<")"<<"\n";
cout<<"终点为:("<< last.Getx()<<","<<last.Gety()<<")"<<endl;
}
};
void main(void)
{Point *m;
Point n(80,90);
float a,b;
cout<<"请依次输入终点的x坐标和Y坐标"<<endl;
cin>>a>>b;
m=new Point(a,b);
Line myline(10,20,30,40);
myline.getline();
cout<<"m is: ("<<m->Getx<<endl;//////这个位置出现错误 应该怎么改呢
delete m;
} 展开
class Point
{private:
float x;
float y;
public:
Point(float x,float y)
{this->x=x;
this->y=y;
}
Point(Point &t):
x(t.x),y(t.y)
{
}
~Point(void)
{}
void setx(float x)
{this->x=x;
}
void sety(float y)
{this->y=y;
}
float Getx(void) const
{return x;
}
float Gety(void) const
{return y;
}
};
class Line
{ private:
Point first;
Point last;
public:
Line(Point &a,Point &b) :
first(a),last(b)
{
}
Line(float a,float b,float c,float d):
first(a,b),last(c,d)
{
}
~Line(void)
{}
void getline(void)
{ cout<<"起始点为: ("<<first.Getx()<<","<<first.Gety()<<")"<<"\n";
cout<<"终点为:("<< last.Getx()<<","<<last.Gety()<<")"<<endl;
}
};
void main(void)
{Point *m;
Point n(80,90);
float a,b;
cout<<"请依次输入终点的x坐标和Y坐标"<<endl;
cin>>a>>b;
m=new Point(a,b);
Line myline(10,20,30,40);
myline.getline();
cout<<"m is: ("<<m->Getx<<endl;//////这个位置出现错误 应该怎么改呢
delete m;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询