CS60_2008-09-25_Week03_2

CS60_2008-09-25_Week03_2 - CMPSC 60 Week 3: Thursday...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMPSC 60 Week 3: Thursday December 9, 2008 Operator overloading As member functions const Money Money::operator +(const Money& secondOperand) const {...} const Money return type Money::operator + scope and name of operator const Money& secondOperand speci es expected parameter type and resulting name referenced object isn't to be modi ed const speci es that the called object also isn't to be modi ed ... Money diffAmount = yourAmount - myAmount; Money diffAmount declares and creates a new Money object to be initialized yourAmount - myAmount calls yourAmount.operator +(myAmount) const Money& secondOperand speci es expected parameter type and resulting name const speci es that the argument isn't to be modi ed Advantages Member functions Automatic type conversion Access to private variables Symmetric w.r.t. +, -, ==, etc. (for objects of same type) Drawbacks Just try 1 + myAmount ......
View Full Document

This note was uploaded on 12/09/2008 for the course CS 60 taught by Professor Holl during the Fall '97 term at UCSB.

Page1 / 3

CS60_2008-09-25_Week03_2 - CMPSC 60 Week 3: Thursday...

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

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