slides-7

Slides-7 - Data Structures CSCI 102 Housekeeping(Lecture 8 Lab#4(Exceptions not ready yet Sorry Will get it done either tonight or tomorrow Due

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

View Full Document Right Arrow Icon
1 Data Structures - CSCI 102 Copyright © William C. Cheng Housekeeping (Lecture 8 - 2/3/2011) Lab #4 (Exceptions) not ready yet! Sorry! Due next week during your lab session HW2 (Extending the Video Game Database) due on 2/14 Quite a few students did not turn in HW1 No design doc is required for this lab Will get it done either tonight or tomorrow Questions? If you think you are in trouble, the best thing to do is to look for help (come see me or one of the TAs)
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 Data Structures - CSCI 102 Copyright © William C. Cheng CS102 C++ Operator Overloading Bill Cheng http://merlot.usc.edu/cs102-s11
Background image of page 2
Polymorphism (Ch 13) Virtual functions Abstract classes Interfaces C Structs (Ch 10) Topics to cover 3 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Object-Oriented Programming C++ Classes (Ch 11) Constructors Destructors Member functions Exceptions (Ch 15) Namespaces (Ch 8) Operator Overloading (Ch 14) Class Composition & Inheritance (Ch 12)
Background image of page 3

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

View Full DocumentRight Arrow Icon
They work on built-in types (e.g. int , string ) C++ has tons of built-in operators (e.g. +,-,<<, etc.) 4 Data Structures - CSCI 102 Copyright © William C. Cheng Operator Overloading They don’t work on your own classes! string a = "hello " ; string b = " world!" ; string c = a + b; //addition cout << c << endl; //print to console String is a class, so why does this work? Since C++ doesn’t know how to do this stuff by default, we have to tell it how
Background image of page 4
You can only overload an operator that has at least one user defined type (i.e. you can’t overload " int + int ") Rules 5 Data Structures - CSCI 102 Copyright © William C. Cheng Operator Overloading You can only overload existing operators, you can’t create your own new ones All operators keep their normal associativity & precedence You can’t overload any of these :: . -> .* ?: sizeof
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Data Structures - CSCI 102 Copyright © William C. Cheng The Point Class class Point { private : int x; int y; public : Point() { x= 0 ; y= 0 ; } Point( int newx, int newy) { x=newx; y=newy; } int getX() const { return x; } int getY() const { return y; } void setX( int newx) { x=newx; } void setY( int newy) { y=newy; } };
Background image of page 6
call somewhere behind the scenes Point p1( 10 , 10 ), p2( 50 , 50 ); Point p3 = p1 + p2; When you see something like this: 7 Data Structures - CSCI 102 Copyright © William C. Cheng The + Operator You should really picture it like this: It can be, but it doesn’t really need to be (no changes are made to p1 or p2) Should this function be a member of the Point class? Could we get access to the private data of "a" and "b" without being part of class "Point"? Point
Background image of page 7

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

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

This note was uploaded on 02/17/2011 for the course CSI 102 taught by Professor Billcheng during the Spring '11 term at USC.

Page1 / 29

Slides-7 - Data Structures CSCI 102 Housekeeping(Lecture 8 Lab#4(Exceptions not ready yet Sorry Will get it done either tonight or tomorrow Due

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

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