重载运算符=错误
Overloading operator = error
我试图创建一个堆栈,但由于重载my=运算符而收到错误。堆栈的类型为template。这是代码
template <typename T>
T& ::stack& operator =(const stack& other)
{
if (this == &other) return *this;
copy(other.stack1[0], other.stack1[other.size], stack1[0]);
return *this;
}
任何帮助都将不胜感激。感谢
请尝试以下签名
template <typename T>
stack<T>& stack<T>:: operator =(const stack<T>& other)
尝试:
template <typename T>
stack<T>& stack<T>::operator =(const stack& other)
{
if (this == &other) return *this;
copy(other.stack1[0], other.stack1[other.size], stack1[0]);
return *this;
}
除了运算符的声明不正确之外,如果stack1是数组,则运算符体内似乎也存在标准算法副本的错误使用
我只能假设操作员应该看起来像
template <typename T>
stack<T> & stack<T>::operator =( const stack<T> &other )
{
if ( this == &other ) return *this;
this->size = other.size;
copy( other.stack1, other.stack1 + other.size, this->stack1 );
return *this;
}
相关文章:
- 在运算符重载定义中使用成员函数(const错误)
- 逻辑运算符上出现错误代码 a')'
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C++:需要帮助了解运算符重载错误
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- C++分数混合比较运算符错误
- 为什么我收到错误:"运算符<<不匹配?
- 迭代器类的重载前缀增量运算符会引发分段错误
- 在 boost::qi 中使用过多的替代运算符会导致分段错误
- 调用运算符时出现链接器错误<<,如何解决?
- 错误:表达式必须具有算术、无作用域枚举或带有运算符重载的指针类型
- 解决错误:运算符 [] 不匹配
- 提升错误:"运算符=="的重载不明确
- 字符串输入中没有匹配的错误运算符错误
- 错误:运算符 = IN C++ 不匹配
- QT 创建器错误(运算符 + 不匹配)
- 错误C++运算符重载
- 错误:运算符==不匹配
- C++ 语法和编译器错误 - 运算符不匹配<<
- C++错误--运算符=不匹配