Given the following classes:
class A {
int a;
public:
//..
};
class B : public A {
int b;
public:
//.....
};
How can I implements operator+=
in class B
so that given B b1(.. , ..);
and B b2(.. , .. );
If I will do b1+=b2;
so I will get in b1
the following value for his fields:
b1.a = b1.a + b2.a ,and b1.b = b1.b + b2.b
In the following case:
class A {
protected:
int a;
public:
//..
};
class B : public A {
int b;
public:
B& operator+=(const B& bb){
this->a += bb.a; // error..
this->b += bb.b;
return *this;
};
My problem is how can I get the fields of class A
..?