Inheritance and Assignment

The assignment operator, as mentioned earlier, is one member function that is not inherited. Let's look more closely at the topic of assignment and inheritance. First, some basics. Consider the following code:

BankAccount darf("Darfa Flemwit", 121234, 100);
BankAccount temp1;
Overdraft bip("Bipp Fardbag", 212143, 200);
Overdraft temp2;
temp1 = darf;
temp2 = bip;

The assignments to temp1 and temp2 are equivalent to the following function calls:

temp1.operator=(darf);  // call #1
temp2.operator=(bip);   // call #2

Because call #1 is invoked by a BankAccount object, the compiler will look for a BankAccount::operator=() function. Because the argument also is a BankAccount object, the compiler will look for a function that ...

Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.