Lecture250 - Operator Overloading booloperator>(accta,acctb...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 1 -- 1 Computer Science I - Martin Hardwick Operator Overloading bool operator >(acct a, acct b) { return a.get_num() > b.get_num();  }  { os << “Name:“ << a.get_name(); os << “ Balance:“ << a.get_bal();      return os; } acct operator + (acct a, acct b)  { return acct (a.get_num(),  a.get_name(), a.get_bal() + b.get_bal()); }       Remember the bank account example. We can enrich this example by using operator overloading The code on the left defines The meaning of > for bank  accounts A special version of << for  bank accounts A plus function for bank  accounts that returns the  value of a with b’s balance  added
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Lecture 1 -- 2 Computer Science I - Martin Hardwick Operator overloading and sort class acct { // bank account data private: int num; // account number string name; // owner of account double balance; // balance in account
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

Lecture250 - Operator Overloading booloperator>(accta,acctb...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online