我之前正在使用此代码但是有一个新问题,旧版本的链接是Bloodshed Dev-C++ compiler errors *Binary Trees。
我有一个错误,在函数'int main()'中声明没有匹配函数调用'binaryTreeType :: insert(int&)'候选者是:void binaryTreeType :: insert()[with elemType = int] not真的很确定这是什么。代码发布在任何帮助之下,感谢提前感谢。
#include <iostream>
using namespace std;
template <class elemType>
struct nodeType
{
int data;
nodeType *lLink;
nodeType *rLink;
};
template <class elemType>
class binaryTreeType //main class
{
public:
binaryTreeType(); //constructor
~binaryTreeType(); //destructor
void swapSubtreeNodes(); //declares swapSubtreeNodes
void swapSubtreeNodes(nodeType<elemType>*);
void insert();
void printTree();
private:
nodeType<elemType>*root; //declares root pointer
nodeType<elemType> *temp; //declares root pointer
};
template <class elemType>
void binaryTreeType<elemType>::swapSubtreeNodes()
{
swapSubtreeNodes(root); //displays new root
}
template <class elemType>
void binaryTreeType<elemType>::swapSubtreeNodes(nodeType<elemType> *p)
{
root = temp;
nodeType<elemType> *root; //pointer for root
nodeType<elemType> *temp; //pointer for temp
if (p == NULL) //checks for empty pointer
{
return;
}
else
{
swapSubtreeNodes(p->lLink); //do the subtrees
swapSubtreeNodes(p->rLink);
temp = p->lLink; //swap the pointers
p->lLink = p->rLink;
p->rLink = temp;
}
root = temp; //root set equal to temp
}
int main()
{
binaryTreeType<int> (tree);
int num;
cout << "This is how we swap'em" << endl;
cout << "Insert number (press enter after each one entered)." << endl;
cout << "Enter -999 to complete" << endl;
binaryTreeType<int> (insert);
cin >> num;
while (num != -999)
{
tree.insert(num);
cin >> num;
}
cout << "The unswapped binary tree looks like this: " << endl;
tree.printTree();
cout << endl;
cout << "The swapped binary tree looks like this: " << endl;
tree.swapSubtreeNodes();
tree.printTree();
cout << endl;
}
答案 0 :(得分:1)
模板成员函数binaryTreeType<elemType>::insert()
不带参数。代码尝试使用类型为int
的参数调用它。
答案 1 :(得分:1)
您的insert
方法声明不会带任何参数。