I have the following code:
class Rectangle
{
protected:
int a, b;
public:
Rectangle(int a, int b) : a(a), b(b) {}
int area() { return a*b; }
Rectangle operator+(const Rectangle & other)
{
Rectangle temp(0, 0);
temp.a = a + other.a;
temp.b = b + other.b;
return temp;
}
void operator=(const Rectangle & other)
{
a = other.a;
b = other.b;
}
};
class Square : public Rectangle
{
public:
Square(int a) : Rectangle(a, a) {}
};
int main()
{
Square s1(3);
Square s2(1);
cout << (s1 + s2).area();
s1 = s1 + s2;
}
The cout << (s1 + s2).area();
is OK but at s1 = s1 + s2;
compiler gives me an error:
no match for 'operator=' (operand types are 'Square' and 'Rectangle')
Why this line does not work?