我一直在为俄勒冈理工大学的C++课程项目工作,但我遇到了一个错误,即使我的教授也无法帮助我。 我一直在尝试使用移动构造函数,但我不断收到以下错误:
函数“Shapes :: operator =(const Shapes&)”(隐式声明)不能被引用-第31行
“Shapes :: operator =(const Shapes&)”:尝试引用已删除的函数-第31行
// Shapes.h
#ifndef LAB1_SHAPES_H
#define LAB1_SHAPES_H
class Shapes {
protected:
float m_width;
float m_area;
float m_perimeter;
public:
Shapes() {
m_width = 0;
m_area = m_width * m_width;
m_perimeter = 4 * m_width;
}
Shapes(float x) {
if (x > 0) {
m_width = x;
}
m_area = m_width * m_width;
m_perimeter = 4 * m_width;
}
Shapes(Shapes&& move) noexcept {
*this = move;
}
Shapes(const Shapes& copy) {
m_width = copy.m_width;
m_area = m_width * m_width;
m_perimeter = 4 * m_width;
}
float getWidth() const {
return m_width;
}
float getArea() const {
return m_area;
}
float getPerimeter() const {
return m_perimeter;
}
};
#endif //LAB1_SHAPES_H