Skip to content
Related Articles

Related Articles

Is assignment operator inherited?

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 29 Mar, 2022
Improve Article
Save Article

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.

using namespace std;
class A {
   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); //calling base class assignment operator function 
                    // using derived class
  return 0;

Output: base class assignment operator called

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!