gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:54 25 4
gpt4 key购买 nike

我正在尝试实现一个面向对象的二叉树,但是,我收到了重载构造函数调用不明确的错误消息。问题是我确实有必要的构造函数,但 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com