Ambigous constructor

I have problem with ambiguous constractor
When I call the empty cosntractor ,I have an error call of overloaded thing() is ambiguous.
Thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>

using namespace std;

class thing
{
    double something;
public:
    thing();
    thing(int);
    thing(double);

    ~thing();
    void setthing(double);
    double getthing();
    void writeThis();
};
thing:: thing(){

  cout <<"Empty constr"<<endl;
}
thing::thing(double i=0.)
{
    cout <<"double constr"<<endl;
}
thing::thing(int i)
{
cout<<"Int constr"<<endl;
}
thing::~thing()
{
    cout<<"Distracted"<<endl;
}
void thing::setthing(double i=0.)
{
    something=i;
}
double thing::getthing()
{
    return something;
}
void thing::writeThis()
{
    cout<<this<<endl;
}
int main()
{
    thing obj1;
    thing obj2(43.2);
    obj1.writeThis();
    obj2.writeThis();
//obj2.writeThis();

}

You gave a default value to the double constructor, so two constructors can be called without arguments. C++ has no way to know which one you want. Either remove the default value or the parameterless c-tor.
Topic archived. No new replies allowed.