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

标签 c++ constructor 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*)

最佳答案

你的两个带有默认参数的构造函数“重叠”:

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

和:

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

这两者都可以匹配一个只有 int 或只有一个 int 和一个 Node * 的调用。

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

关于c++ - 重载构造函数的调用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27176541/

相关文章:

c++ - 比较 map 对象及其引用 C++

c++ - Constexpr变量评估

c - Ruby C 扩展中构造函数的奇怪行为

python - 在python中覆盖列表的构造函数

c++ - 不明确的模板类构造函数

c++ - 模板参数不明确 : could not deduce template argument

c++ - 为什么将 char 数组复制到结构中时 memcpy 不起作用?

c++ - 当给定索引处的列尚未创建时,setSectionResizeMode() 崩溃

java - Constructor中如何处理Writer、Result、OutputStream?

c# - 由于注释中的 cref 引用,在 C# 应用程序中出现模糊引用错误?