引用类型的初始化无效?

时间:2014-09-24 23:35:32

标签: c++ compiler-errors

怎么回事?这是它引用的功能。我试图让它作为一个复制构造函数

template <class T>
const queue<Base>& queue<T>::operator=(const queue<Base> &q){
// Doesn't need to copy if they are the same object
if (this != &q){
    delete [] data;

    length = q.length;
    capacity = q.capacity;
    front = q.front;

    data = new T[capacity];

    for (int i = 0; i < capacity; i++){
        data[i] = q.data[i];
    }
}

return this;
}

1 个答案:

答案 0 :(得分:2)

这是你的错误

return this;

this是一个指针。您的operator =被声明为返回引用。指针无法转换为引用。这是错误消息告诉您的内容。