class A
{
int Avalue;
A& operator=(A& copyMe)
{
Avalue = copyMe.Avalue;
return *this;
}
}
class B:public A
{
int Bvalue;
B& operator=(B& copyMe)
{
Bvalue = copyMe.Bvalue
return *this;
}
}
How to invoke the A or the base class assignment operator from the B’s assignment operator?.How to handle A’s return reference from the assignment operator call.
All operators can be thought of as a bit of clever functions, but that’s just courtesy of the compiler which is smart enough to infer what are the given operands and pass them into your override. It’s a great extensible way of adding nice syntactic sugar in situations where it makes sense, but because of their usual usage, people cannot really see that this is valid, but when you observe your definitions of the overrides, they look like functions and act like functions. So, simply use the scope operator
::to access the public parts of A’s interface.Do note you’re missing several semicolons and also, classes default to
privateaccess. To gain access to the copy assignment operator in A, you need to specify it as public: