错误:调用'TNode<Student>::TNode<const Student&)'没有匹配函数
error: no matching function for call to 'TNode<Student>::TNode<const Student&)'
每当我想使用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&)[withWhatever=Student]:
Tree.c:140:错误:没有用于调用"TNode::TNode(const Student&)"的匹配函数
Tree.c:48:注意:候选者是:TNode::TNode(const Whatever&,TNode&)[withWhatever=Student]
Tree.c:40:注意:TNode::TNode(const Whatever&,Tree&)[withWhatever=Student]
树.c:31:注意:TNode::TNode(const TNode&)
有人知道如何修复这个错误吗??
两个TNode
构造函数都接受两个参数。你只通过了一个。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 如何显式调用运算符<<
- 模板操作员&lt;未打电话
- C / CUDA中的模板方法是3个角括号(&lt;&lt;&lt;)
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- C 建造者Clang STD :: Sill,找不到超载的操作员&lt;
- 为什么STD :: MAP需要操作员&lt;以及我如何写一个
- 为什么“操作员”需要const但不是为“运营商&lt;”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 错误:'void TNode::inititTree(TNode*)' 的原型与类 'TNode' 中的任何原型都不匹配
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 左角支架解释为操作员&lt;而不是模板参数
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- 超载操作员&lt;&lt; - 必须是二进制操作员