Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Is assignment operator inherited?

  • Difficulty Level : Medium
  • Last Updated : 29 May, 2017

In C++, like other functions, assignement 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.

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

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
Recommended Articles
Page :

Start Your Coding Journey Now!