Is assignment operator inherited?
Last Updated :
29 Mar, 2022
In C++, like other functions, assignment operator function is inherited in derived class.
For example, in the following program, base class assignment operator function can be accessed using the derived class object.
#include<iostream>
using namespace std;
class A {
public :
A & operator= (A &a) {
cout<< " base class assignment operator called " ;
return * this ;
}
};
class B: public A { };
int main()
{
B a, b;
a.A::operator=(b);
getchar ();
return 0;
}
|
Output: base class assignment operator called
Share your thoughts in the comments
Please Login to comment...