简体   繁体   English

重载构造函数的调用不明确

[英]Call of overloaded constructor is ambiguous

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. 问题是我确实有必要的构造函数,但C ++似乎无法识别它。

My code: http://pastebin.com/PM9PDYAN 我的代码: 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*)

Your two constructors with default arguments "overlap": 具有默认参数“ 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 * . 这两个都可以使一个int或一个intNode *的调用匹配。

Looks like there are other overlapping constructors as well. 看起来还有其他重叠的构造函数。

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

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); 如果用户说Node node(5) ,则编译器不知道您的意思是Node(const int& 5, Node* = nullptr); or Node(const int& 5) . Node(const int& 5)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM