c++ - < token 之前的错误预期初始值设定项

标签 c++ templates overloading operator-keyword

我正在重载赋值运算符,并收到此错误。无法解决。

这是模板类 binTree 中的原型(prototype)

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)

最佳答案

来自你的声明

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

您的类(class)类型是

binTree<T>::

您的成员(member)是

operator =(const BinTree<T>& p)  

你的返回类型是

binTree<T>&

所以你的定义是

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

关于c++ - < token 之前的错误预期初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9865470/

相关文章:

java - 将 Scala 运算符添加到最终的 Java 类

c++ - 指定 cmath 的 pow 函数而不是本地声明的函数

c++ - 如何在多态性中为指定类型分配内存?

c++ - 派生模板类不调用构造函数

c++ - 用模板化类型指定模板化类型的类型

c++ - 使用模板和 boost 功能

c# - 带有 while (true) 的特殊重载决议

c++ - 在程序中包含图形界面

c++ - QT中如何同步发送http请求?

C++:处理不同大小数组的函数