Call of overloaded constructor is ambiguous

5k views Asked by At

I am trying to implement an object-oriented binary tree, however, I get the error message of a call of an overloaded constructor being ambiguous. The problem is that I really do have the necessary constructor, yet C++ doesn't seem to recognize it.

My code: http://pastebin.com/PM9PDYAN

The error message:

56  36  In constructor 'Node::Node(const int&, Node*, Node*, const int&)':
56  36  [Error] call of overloaded 'Node(const int&, Node* const)' is ambiguous
17  3   [Note] Node::Node(const int&, Node*)
15  3   [Note] Node::Node(const int&, const int&, Node*) <near match>
15  3   [Note] no known conversion for argument 2 from 'Node* const' to 'const int&'
37  1   [Note] Node::Node(const int&, Node*, Node*, Node*)
3

There are 3 answers

0
Turix On BEST ANSWER

Your two constructors with default arguments "overlap":

Node(const int&, Node* = nullptr, Node* = nullptr, Node* = nullptr);

And:

Node(const int&, Node* = nullptr);

Both of these could match a call with just an int or just an int and a Node *.

Looks like there are other overlapping constructors as well.

0
ravi On
Node(const int&, Node* = nullptr, Node* = nullptr, Node* = nullptr);
Node(const int&);
Node(const int&, Node* = nullptr);

These three are ambigous calls as compiler won't be able to resolve the call if you call it by:-

Node node(1);
0
Ying Xiong On

The following constructors are ambiguous (among others). If the user say Node node(5), the compilor does not know whether you meant Node(const int& 5, Node* = nullptr); or Node(const int& 5).

Node(const int&, Node* = nullptr);
Node(const int&);