首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

…error C2664: '_thiscall point:point(const class point &)'

2012-07-23 
求助…error C2664: __thiscall point::point(const class point &) :#includeiostreamusing namespace

求助…error C2664: '__thiscall point::point(const class point &)' :
#include<iostream>
using namespace std;
class point
{
private:
double fx,fy;
public:
point();
point(double x,double y);
void showpoint();
};
point::point()
{
fx=0.0;
fy=0.0;
}
point::point(double x,double y)
{
fx=x;
fy=y;
}
void point::showpoint()
{
cout<<fx<<" "<<fy<<endl;
}
void main()
{
point p1;
cout<<"the fx and fy of p1:";
p1.showpoint();
point p2(10);
cout<<"the fx and fy of p2:";
p2.showpoint();
point p3(1.1,2.2);
cout<<"the fx and fy of p3:";
p3.showpoint();
}
构造函数的重载.cpp
C:\Users\blues\Desktop\say 嘎嘎\构造函数的重载.cpp(31) : error C2664: '__thiscall point::point(const class point &)' : cannot convert parameter 1 from 'const int' to 'const class point &'
  Reason: cannot convert from 'const int' to 'const class point'
  No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.

构造函数的重载.obj - 1 error(s), 0 warning(s)


[解决办法]

C/C++ code
(31) : error C2664: “point::point(const point &)”: 不能将参数 1 从“int”转换为“const point &”  原因如下: 无法从“int”转换为“const point”  无构造函数可以接受源类型,或构造函数重载决策不明确
[解决办法]
没有提供一个参数的 构造函数啊。。
[解决办法]
这样改一下:
C/C++ code
class point{private:    double fx,fy;public://    point();    point(double x=0.0,double y=0.0);//默认参数    void showpoint();};/*point::point(){    fx=0.0;    fy=0.0;}*/ 

热点排行