For the sake of completeness, I want to provide me with a trivial unary + operator as well.
The unary operators should be immutable, I think. If I make operator-() return a copy of the negated object, a statement -obj=other; (both obj and other are objects of type Complex) will not compile. However, if I make operator+() return the object itself, another statement +obj=other; will compile.
The problem is I cannot use const in the following snippet. What does the error mean?
Complex& operator+() const
{
return *this;
}
Complete Code
class Complex
{
private:
double re;
double im;
public:
// others are intentionally removed for the sake of simplicity
Complex operator-() const
{
return Complex{-re,-im};
}
Complex& operator+() const
{
return *this;
}
}
