Is assignment operator inherited?
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.
#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; } |
chevron_right
filter_none
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.
Recommended Posts:
- What all is inherited from parent class in C++?
- Operands for sizeof operator
- Copy constructor vs assignment operator in C++
- Self assignment check in assignment operator
- Rules for operator overloading
- Result of comma operator as l-value in C and C++
- Comma operator should be used carefully
- C/C++ Ternary Operator - Some Interesting Observations
- When should we write our own assignment operator in C++?
- Default Assignment Operator and References
- Can we use % operator on floating point numbers?
- Scope Resolution Operator Versus this pointer in C++?
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Placement new operator in C++
- Operator Overloading in C++



