gpt4 book ai didi

c++ - 错误 : no matching function for call to 'TNode::TNode
转载 作者:行者123 更新时间:2023-11-28 05:57:52 27 4
gpt4 key购买 nike

每当我想在 C++ 上使用模板在二叉树上添加一个元素时,我就会遇到这个错误,而且我很难修复它,

所以这里是我的代码是 Tree.c 文件:

template <class Whatever>
ostream & operator << (ostream &, const TNode<Whatever> &);

template <class Whatever>
struct TNode {
long balance;
Whatever data;
long height;
TNode<Whatever>* left;
long & occupancy;
TNode<Whatever>* right;
unsigned long & tree_count;

TNode (const Whatever & element, Tree<Whatever> & theTree)
:balance (0), data (element), height(0), left(0),
occupancy(theTree.occupancy), right(0),
tree_count (theTree.tree_count) {
occupancy++;
}

TNode (const Whatever & element, TNode<Whatever> & parentTNode)
: balance(0), data (element), height (0), left (0),
occupancy(parentTNode.occupancy), right (0),
tree_count (parentTNode.tree_count) {
occupancy++;
}


template <class Whatever>
unsigned long Tree<Whatever> :: Insert (const Whatever & element) {
//check to see if the tree is empty
if(root == NULL)
{
root = new TNode<Whatever>(element); //this is keep on giving me the no
//matching function error
return TRUE;
}

return FALSE;
}

这是我的 Tree.h 文件:

template <class Whatever>
struct TNode;

template <class Whatever>
class Tree {
friend struct TNode<Whatever>;
long occupancy;
TNode<Whatever> * root;
unsigned long tree_count;
static int debug;
public:
//here are my constructor and destructor

unsigned long Insert (const Whatever &);

这是我的 Driver.h 文件:

class Student {
friend ostream & operator << (ostream &, const Student &);
char name[20];
long studentnum;
public:
//here are my constructor,copy constructor, and deconstructor

每当我尝试编译时,我都会不断收到错误消息,

Tree.c: 在成员函数 'long unsigned int Tree::Insert(const Whatever&) [with Whatever = Student] 中:

Tree.c:140: 错误:没有匹配函数来调用 'TNode::TNode(const Student&)'

Tree.c:48: 注意:候选人是:TNode::TNode(const Whatever&, TNode&) [with Whatever = Student]

Tree.c:40: 注意:TNode::TNode(const Whatever&, Tree&) [with Whatever = Student]

Tree.c:31: 注意:TNode::TNode(const TNode&)

有人知道如何解决这个错误吗??

最佳答案

您的两个 TNode 构造函数都有两个参数。你只超过了一个。

关于c++ - 错误 : no matching function for call to 'TNode<Student>::TNode<const Student&)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33812700/

27 4 0

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