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

这个为什么会发出警告呢,小弟我看不出有关问题

2012-06-17 
这个为什么会发出警告呢,我看不出问题?C/C++ codestruct Point{int aint bPoint(int c1){acbc}Poin

这个为什么会发出警告呢,我看不出问题?

C/C++ code
struct Point{    int a;    int b;    Point(int c=1)    {        a=c;        b=c;    }    Point()    {        a=100;        b=123;    }    Point(int x,int y)    {        a=x;        b=y;    }    void Output()    {        cout<<a<<endl<<b<<endl;    }    void Output(int x,int y)    {        a=x;        b=y;        cout<<a<<endl<<b<<endl;    }    ~Point()    {        cout<<"删除该类..."<<endl;    }};


警告是如下:
warning C4520: 'Point' : multiple default constructors specified

警告 C4520, 类Point: 多重的默认构造函数不够明确?
  我自己觉得这里三个构造函数没什么问题,一个不带参数,一个1个参数,一个两个参数。
为什么会发出警告呢。


[解决办法]
Point(int c=1)
{
a=c;
b=c;
}

你这里 C = 1 带了缺省默认参 和不带参的构造引发的不明确
[解决办法]
当你调用无参构造的时候,根本不知道是调用第一个还是第二个,这时候编译器直接给error都不过分

热点排行