急!急求帮助!=操作符重载
template <class T>
SeqList<T>& SeqList<T>::operator=(SeqList<T>& L)
{
if(this == &L) return *this;
T value;
int n = L.Length();
T* ptr = &L; //error C2440: 'initializing' : cannot convert from 'class SeqList<int> *' to 'int *'
while(n--)
*this++ = *srcptr++; // error C2105: '++' needs l-value
return *this;
}
//error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)这个错误出在*this++ = *srcptr++; 请问上述三个错误如何处理,谢谢
SeqList<T>& SeqList<T>::operator=(SeqList<T>& L)
{
if(this == &L) return *this;
T value;
int n = L.Length();
T* ptr = &L; //error C2440: 'initializing' : cannot convert from 'class SeqList<int> *' to 'int *'
while(n--)
*this++ = *srcptr++; // error C2105: '++' needs l-value
return *this;
}
//error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)这个错误出在*this++ = *srcptr++; 请问上述三个错误如何处理,谢谢
...全文
相关推荐
C++ operator关键字(重载操作符)的用法详解
选择哪种方式取决于操作符的性质和需求。通常,如果操作符需要访问类的私有或保护成员,或者操作符作用于类的单个实例(如`++`),则应作为成员函数实现。对于对称操作符(如`==`、`!
实现操作符重载 实现操作符重载
四、常见操作符重载示例1. 自增自减操作符:`++`和`--`2. 赋值操作符:`=`3. 流输入输出操作符:`<<`和`>>`4. 比较操作符:`==`、`!
详解C++赋值操作符重载
"C++赋值操作符重载的原理与注意事项"C++中的赋值操作符`=`是我们编程中常用的一个符号,它用于将值从右边的表达式复制到左边的变量。然而,在某些特定场景下,特别是涉及到自定义类型(如类或结构体
C++输入输出操作符重载的深入分析
在C++编程语言中,操作符重载是一种强大的特性,允许程序员为自定义类型赋予新的操作符含义。本文将深入探讨C++中的输入输出操作符重载,这对于理解和使用自定义类型进行I/O操作至关重要。
C++操作符优先级、可重载型
掌握操作符优先级和可重载性对于编写高效且无误的C++代码至关重要,因为正确理解它们可以帮助我们写出更清晰、更易于理解的表达式。


