Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Is assignment operator inherited?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like 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.




#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); //calling base class assignment operator function 
                    // using derived class
  getchar();
  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
Last Updated : 29 Mar, 2022
Like Article
Save Article
Similar Reads