lecture30 Operator Overloading (2)

lecture30 Operator Overloading (2) - CMPT 128 Introduction...

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

View Full Document Right Arrow Icon
1 © Janice Regan, CMPT 128, February. 2007 CMPT 128: Introduction to Computing Science for Engineering Students Operator Overloading (2)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Other Overloads Predefined versions work for bool types Recall: use "short-circuit evaluation" When overloaded no longer uses short-circuit Uses "complete evaluation" instead Contrary to expectations Generally should not overload these operators
Background image of page 2
3 Friend Functions Friend functions are nonmember functions Most nonmember functions access the class’s private data using accessor and mutator functions Very inefficient due to extra overhead of function calls Friends are a special kind of nonmember function that can directly access a class’s private data No overhead, more efficient Useful to make nonmember operator overloads friends Not strictly consistent with OO design, breaks encapsulation!
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Friend Functions Friend function of a class Not a member function Has direct access to private members using the object.attribute notation Specified in class definition, using keyword friend Definition is a a non-member function Type functionName( argument list) NOT Type class::functionName( argument list)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/18/2010 for the course CMPT 128 taught by Professor Regan during the Spring '08 term at Simon Fraser.

Page1 / 15

lecture30 Operator Overloading (2) - CMPT 128 Introduction...

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

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