2012-03-26 48 views
1

我重载赋值运算符,并正在此错误。解决不了。错误预期初始化之前<令牌

这里是模板类里面的原型二叉树

binTree <T>& operator = (const binTree <T>&); // assignment operator 

这里是方法

// assignment operator 
template <class T> 
void binTree <T>::binTree <T>& operator = (const binTree <T>& p) 
{ 
    if(this != &p) 
    { 
     clear(root); // clear tree 
     root = copy(p.root); // copy tree 
    }  
    return *this; 
} 

我收到这条线上的错误

void binTree <T>::binTree <T>& operator = (const binTree <T>& p) 

回答

4

的开始从你的宣言

binTree <T>& operator = (const binTree <T>&); 

你的类的类型是

binTree<T>:: 

您构件是

operator =(const BinTree<T>& p) 

你的返回类型为

binTree<T>& 

所以,你的定义是

binTree<T>& binTree<T>::operator= (const binTree<T>& p){ 
    // bug-free code goes here 
} 
+3

@ user1236803非常欢迎。您可以通过选中问题旁边的复选标记将问题标记为已解决。 – 2012-03-26 01:17:28

0

你不需要第二bintree<T>在返回类型

binTree <T>& operator = (const binTree <T>& p) 

编辑:删除void从线(太快复制粘贴的结果)

+0

给我确切的同样的错误 – user1236803 2012-03-26 01:13:30

+0

你是对的,你不需要'void'要么 - 仓促复印通粘贴...(更正) – Attila 2012-03-26 01:55:17

相关问题