Call of overloaded constructor is ambiguous

时光怂恿深爱的人放手 提交于 2019-12-20 04:55:18

问题


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*)

回答1:


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.




回答2:


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);



回答3:


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&);


来源:https://stackoverflow.com/questions/27176541/call-of-overloaded-constructor-is-ambiguous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!