帮我看看这个关于二叉数的错误
我这样定义一个二叉数 BinaryTree c;
编译时出现这样一个错误,:\study\data\zuoye\seventh\build.cpp(124) : error C2955: 'BinaryTree' : use of class template requires template argument list
D:\study\data\zuoye\seventh\build.cpp(52) : see declaration of 'BinaryTree'
高手帮我看看怎么回事啊?
以下是我的原程序
#include<iostream>
#include<fstream>
using namespace std;
int j=1;
template<class T> class BinaryTree;
template<class T>
class BinaryTreeNode
{
friend class BinaryTree<T>;
public:
BinaryTreeNode() {LeftChild=RightChild=0;}
BinaryTreeNode(const T& e)
{data=e;LeftChild=RightChild=0;}
BinaryTreeNode(const T& e,BinaryTreeNode *l,BinaryTreeNode *r)
{data=e;LeftChild=l;RightChild=r;}
private:
T data;
BinaryTreeNode<T> *LeftChild,*RightChild;
};
template<class T>
class BinaryTree
{
public:
BinaryTree() {root=0;};
~BinaryTree(){};
bool Empty() const
{return ((root)? false:true);}
bool Root(T &x) const;
void MakeTree(const T& element,
BinaryTree<T>& left,BinaryTree<T>& right);
void BreakTree(T& element,BinaryTree<T>& left,
BinaryTree<T>& right);
void PreOrder(void(* Visit)(BinaryTreeNode<T> *u))
{PreOrder(Visit,root);}
void InOrder(void(* Visit)(BinaryTreeNode<T> *u))
{InOrder(Visit,root);}
void PreOutput() {PreOrder(Output,root); out<<endl;}
void InOutput() {InOrder(Output,root); out<<endl;}
void Delete() {PostOrder(Free,root); root=0;}
void creattree(int n,int *a,BinaryTreeNode<T> *root);
private:
BinaryTreeNode<T> *root;
void PreOrder(void(*Visit)
(BinaryTreeNode<T> *u),BinaryTreeNode<T> *t);
void InOrder(void(*Visit)
(BinaryTreeNode<T> *u),BinaryTreeNode<T> *t);
static void Tree(BinaryTreeNode<T> *t) {delete t;}
static void Output(BinaryTreeNode<T> *t)
{out<<t->data<<' ';}
static void Add1(BinaryTreeNode<T> *t) {count++;}
int Height(BinaryTreeNode<T> *t) const;
};
template<class T>
bool BinaryTree<T>::Root(T &x)const
{
if(root){x=root->data;return true;}
else return false;
}
template<class T>
void BinaryTree<T>::MakeTree(const T& element,BinaryTree<T>& left,BinaryTree<T>& right)
{
root=new BinaryTreeNode<T>(element,left.root,left.root);
left.root=right.root=0;
}
template<class T>
void BinaryTree<T>::creattree(int n,int *a,BinaryTreeNode<T> *root)
{
*root=new BinaryTreeNode<T>(a[j++]);
if(j<=n){
creattree(n,a,&(*root)->leftchild);
creattree(n,a,&(*root)->rightchild);
}
}
template<class T>
void BinaryTree<T>::BreakTree(T& element,BinaryTree<T>& left,BinaryTree<T>& right)
{
if(! root) throw BadInput();
element=root->data;
left.root=root->LeftChild;
right.root=root->RightChild;
delete root;
root=0;
}
template<class T>
void BinaryTree<T>::PreOrder(void(*Visit)(BinaryTreeNode<T> *u),BinaryTreeNode<T> *t)
{
if(t){Visit(t);
PreOrder(Visit,t->LeftChild);
PreOrder(Visit,t->RightChild);
}
}
template<class T>
void BinaryTree<T>::InOrder(void(*Visit)(BinaryTreeNode<T> *u),BinaryTreeNode<T> *t)
{
if(t){InOrder(Visit,t->LeftChild);
Visit(t);
InOrder(Visit,t->RightChild);
}
}
template<class T>
int BinaryTree<T>::Height(BinaryTreeNode<T> *t) const
{
if(!t) return 0;
int hl=Height(t->LeftChild);
int hr=Height(t->RightChild);
if(hl>hr) return ++hl;
else return ++hr;
}
int main()
{
ifstream in("input.txt");
ofstream out("output.txt");
int i,*a,n;
cin>>n;
a=new int (n+1);
a[0]=0;
for(i=1;i<=n;i++)
{a[i]=i;}
BinaryTree c;
}
问题点数:10、回复次数:1Top
1 楼xpdavis(咕嘟-不想孤独)回复于 2006-06-01 07:41:29 得分 0
BinaryTree c;
-------->
BinaryTree<int> c;
或其它类型Top




