Using parent assignment operator

Let's say I have the following code:
1
2
3
4
5
6
7
8
9
10
struct A
{
   int a;
   operator=(A& obj);
};
struct B : public A
{
   int b;
   B& operator=(B& obj);
}


I basically want B::operator= to be:
1
2
3
4
5
6
B& B::operator=(B& obj)
{
   this->a = obj.a;
   this->b = obj.b;
   return *this;
}

This example is quite banal and easy to do, but what if I had many variables in A? Isn't there a way for me to call A::operator= from within B::operator=, and let it take care of whatever was in the base class? I mean, I know I can literally call A::operator=, but then A would have to have an A::operator=(B& obj) as well. Isn't there a way of using the fact that B inherits from A and let A::operator= deal with the parts of B that it inherited, while B::operator= deals with the rest?

Or does B::operator= need to deal with all the elements, including those passed down by the parent class?
I mean, I know I can literally call A::operator=, but then A would have to have an A::operator=(B& obj) as well.
B is an A, there is no need for that another method. See Liskov substitution principle.

Or does B::operator= need to deal with all the elements, including those passed down by the parent class?
In some cases that could be impossible (private members in the parent class)
From what I understood, that means that I can use A::operator= with a B instead of an A, since the value is taken by reference.

However, how do I make use of that information?

I can't do (just noticed I forgot to put the return type A& on A::operator=):
1
2
3
4
5
6
B& B::operator=(B& obj)
{
   *this = A::operator=(B); 
   this->b = obj.b;
   return *this;
}

Because that asks for an B::operator=(A&)

I also obviously can't do
1
2
3
4
5
6
B& B::operator=(B& obj)
{
   *this A::operator=(B); //pretending it's *this = B
   this->b = obj.b;
   return *this;
}


So, how do I do it?
A::operator( obj ); or if you prefer this->A::operator=(obj);
That is... completely reasonable. Thanks.
Topic archived. No new replies allowed.