繁体   English   中英

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

[英]Call of overloaded constructor is ambiguous

我正在尝试实现一个面向对象的二叉树,但是,我得到了一个重载构造函数调用不明确的错误消息。 问题是我确实有必要的构造函数,但C ++似乎无法识别它。

我的代码: http//pastebin.com/PM9PDYAN

错误信息:

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

具有默认参数“ overlap”的两个构造函数:

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

和:

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

这两个都可以使一个int或一个intNode *的调用匹配。

看起来还有其他重叠的构造函数。

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

这三个是模棱两可的调用,因为如果通过以下方式调用,编译器将无法解析该调用:

Node node(1);

以下构造函数是不明确的(以及其他)。 如果用户说Node node(5) ,则编译器不知道您的意思是Node(const int& 5, Node* = nullptr); 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