lecture-6

lecture-6 - CPSC 223 Algorithms Data Abstract Structures...

• 11

This preview shows pages 1–4. Sign up to view the full content.

9/16/10 1 CPSC 223 Algorithms & Data Abstract Structures Lecture 6: Loose Ends Today … Homework Homework 2 due today Homework 3 assigned Wrap up overloading [Sect. 8.6] Static vs. Dynamic Binding [Sect. 8.2] CPSC 223, Fall 2010 2

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

9/16/10 2 Operator Overloading Operator return values the residual value of the expression containing that operator and its operands pay close attention to the type and value returned returned value allows operator to be used in larger expressions … to be used as an operand in another operator (e.g., a + b + c ) CPSC 223, Fall 2010 3 C/C++ lvalues An “ lvalue An addressable variable (a variable that can be assigned to) What goes on the “ left side ” of an equation, for example: int m = 5; // m is an lvalue 3 = 2; // not allowed, 3 is not an lvalue An lvalue can usually be assigned to … Except when const is used (a non-modifiable lvalue) const int m = 5; CPSC 223, Fall 2010 4
9/16/10 3 C/C++ rvalues An “ rvalue The opposite of an lvalue These values are not assignable (e.g., 5 + 2 = 8 ) Return values can make implementing operators tricky! CPSC 223, Fall 2010 5 Operator Overloading All arithmetic, bitwise, relational, equality, logical, and compound assignment operators can be overloaded The address-of, dereference, increment, decrement, and comma operators can also be overloaded Many operators cannot be overloaded, including scope resolution (::), direct member access (.), direct pointer to member access (.*), conditional operator (?:), size of object operator (sizeof) Operators that must be overloaded as members include assignment (=), subscript ([]), indirect member access operator (->), and indirect pointer to member access operator (->*)

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

This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern