UD CISC 181 - Lecture 25 (3 pages)

Previewing page 1 of 3 page document View the full content.
View Full Document

Lecture 25



Previewing page 1 of actual document.

View the full content.
View Full Document
View Full Document

Lecture 25

90 views

Lecture Notes


Pages:
3
School:
University of Delaware
Course:
Cisc 181 - Introduction to Computer Science II

Unformatted text preview:

2 8 1 Introduction CISC181 Introduction to Computer Science Use operators with objects operator overloading Clearer than function calls for certain classes Operator sensitive to context Examples Dr McCoy Dr Stream insertion bitwise left shift Performs arithmetic on multiple types integers floats etc Lecture 25 December 1 2009 Will discuss when to use operator overloading 1 2003 Prentice Hall Inc All rights reserved 3 4 8 2 Fundamentals of Operator Overloading 8 2 Fundamentals of Operator Overloading Types Using operators on a class object Built in int char or user defined It must be overloaded for that class Exceptions Assignment operator Memberwise assignment between objects Address operator operator Returns address of object Both can be overloaded Can use existing operators with user defined types Cannot create new operators Overloading operators Create a function for the class Name function operator followed by symbol Operator for the addition operator Overloading provides concise notation object2 object1 add object2 object2 object2 object1 2003 Prentice Hall Inc All rights reserved 2003 Prentice Hall Inc All rights reserved 5 6 8 3 Restrictions on Operator Overloading Cannot change How operators act on built in data types I e cannot change integer addition Precedence of operator order of evaluation Use parentheses to force order of operations 8 3 Restrictions on Operator Overloading Operators that can be overloaded new delete new delete Associativity A i ti it l left to right ft t i ht or right to left i ht t l ft Number of operands is unitary only acts on one operand Cannot create new operators Operators must be overloaded explicitly Operators that cannot be overloaded sizeof Overloading does not overload 2003 Prentice Hall Inc All rights reserved 2003 Prentice Hall Inc All rights reserved 1 7 8 8 4 Operator Functions As Class Members Vs As Friend Functions 8 4 Operator Functions As Class Members Vs As Friend Functions Overloaded operator Operator functions



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Lecture 25 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 25 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?