Download presentation
1
ECE 264 Object-Oriented Software Development
Instructor: Dr. Honggang Wang Fall 2012 Lecture 37: Exam 3 Preview
2
Lecture outline Announcements/Reminders General exam information
Lab 10 submission due by tomorrow Project demos due December 7 (Friday) Entire group members must attend Presentation order: Group 1-Group 4 Project documentation (user’s guide, tech report) due December 10 General exam information Q & A Friday? Exam review: what we’ve covered since the last exam (not an exhaustive list!) Destructors Copy constructors Operator overloading Inheritance Basics of base/derived classes Use of constructors Virtual functions Pure virtual functions & abstract classes 4/27/2017 ECE 264: Lecture 37
3
General exam information
8.5” x 11” double-sided sheet of notes allowed; paper based materials allowed Exam date/time: Monday, 12/10, 9:00-9:50 am Exam will be written to (hopefully) take one hour Exam will be held in room: S&E 212 Very similar format to Exams 1 & 2: 3 questions, most of which have multiple parts Question 1: Multiple choice (more ?s, fewer points per ?) Question 2: Understanding code (i.e., given some code, what’s output?) Question 3: Writing short code sequences Sample Questions and solutions will be uploaded Tuesday 4/27/2017 ECE 264: Lecture 37
4
Review: Destructors class-name::~class-name() { }
Destructors called when object destroyed; used for “object cleanup” At end of function When delete is used to deallocate object Often empty, unless object contains dynamically allocated data Destructor is responsible for deleting that data Syntax: class-name::~class-name() { } 4/27/2017 ECE 264: Lecture 16
5
Review: Copy constructors
Called when new object created from existing object Example: Point p2 = p1; Default is shallow copy Need deep copy if object contains Array(s) Dynamically allocated data Must still copy all data members Syntax: class_name::class_name(const class_name &<param_name>) Example: tenInts::tenInts(const tenInts &t){ for (int i=0; i < 10; i++) arr[i] = t.arr[i]; } 4/27/2017 ECE 264: Lecture 37
6
Review: Operator overloading
Allows use of built-in operators with user-defined types Definitions for overloaded operators included in class definition Example (from Point class) double operator –(const Point& rhs); Syntax: Keyword operator is used, followed by the actual operator “Argument” is an object reference of the same type const declarations are optional but often preferred Syntax exceptions: friend functions Has access to class data, but not technically part of class Used if LHS of operation is not of same type as class Example: stream operators (e.g. cin >> h1;) Both sides (of binary operator) must be specified as “arguments” 4/27/2017 ECE 264: Lecture 37
7
Review: Inheritance Create new class (derived class) from existing class (base class) Base class has functionality shared by derived class Can add functions to derived class Can customize base class functionality Can have inheritance hierarchy Syntax example using Rectangle/Square In Square.h, declare class as: class Square : public Rectangle Default constructor for a base class is called automatically in the derived class constructor Ex: Square() calls Rectangle() Will actually traverse inheritance hierarchy, starting at lowest class If derived class needs the parameterized constructor of base class, must explicitly invoke it in initialization list Ex: Square::Square(const Point &p, double s) : Rectangle(s, s, p.getX(), p.getY()) Access visibility: for data/functions to be visible to base & derived class(es), but not clients, declare as protected 4/27/2017 ECE 264: Lecture 37
8
Review: Polymorphism/virtual functions
Polymorphism: Code/operations behave differently in different contexts One example: operator overloading Inheritance-based polymorphism in form of virtual functions Virtual functions allow us to write generic code that works for (hopefully) many specific cases Using pointers to objects allows dynamic binding Base class pointer can be used for derived class object ptr->function() will call version for appropriate class Also useful when Passing function arguments by reference Calling member function inside another member function (implicitly using this pointer) Remember, a class with virtual functions should have a virtual destructor 4/27/2017 ECE 264: Lecture 37
9
Review: Abstract classes
Abstract classes give ability to specify generic class At least some base class functionality is too general to implement use pure virtual function Having pure virtual function(s) makes class abstract Cannot instantiate object of abstract class type Pure virtual function syntax (in .h file): virtual <return_type> <fname>(<args>) = 0; Derived classes must overload pure virtual functions Failure to do so makes derived class abstract! 4/27/2017 ECE 264: Lecture 37
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.